- Add save object
This commit is contained in:
1 parent
54797fafcd
commit
58784dda8a
7 files changed
+74
-21
No files matched your search
@@ -10,6 +10,7 @@
|
||||
#import "PNObjectConfig.h"
|
||||
#import "PNObjectModel.h"
|
||||
|
||||
|
||||
@protocol PNObjectSubclassing <NSObject>
|
||||
|
||||
@required
|
||||
|
||||
@@ -11,6 +11,7 @@
|
||||
#import <NSDate_Utils/NSDate+NSDate_Util.h>
|
||||
#import <AFNetworking/AFNetworking.h>
|
||||
#import "PNObject/PNUser.h"
|
||||
#import "PNObjectConstants.h"
|
||||
|
||||
#define PNOBJECT_DIR @"PNObjects"
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "PNObjectConfig.h"
|
||||
#import "PNObjectConstants.h"
|
||||
|
||||
NSString* const EnvironmentProduction = @"PNObjectConfigEnvProduction";
|
||||
NSString* const EnvironmentStage = @"PNObjectConfigEnvStage";
|
||||
|
||||
@@ -0,0 +1,32 @@
|
||||
//
|
||||
// PNObjectConstants.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 16/01/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import "HTTPStatusCodes.h"
|
||||
|
||||
#ifndef PNObjectConstants_h
|
||||
|
||||
#define PNObjectConstants_h
|
||||
|
||||
#pragma mark Constants
|
||||
|
||||
#define DEF_DOCUMENT_ROOT @"Documents"
|
||||
|
||||
#pragma mark -
|
||||
|
||||
#pragma mark NSLogDebug Macro
|
||||
|
||||
#define FORCE_NO_LOG 0
|
||||
|
||||
#if defined(FORCE_NO_LOG) && FORCE_NO_LOG == 0
|
||||
#define NSLogDebug(format, ...) NSLog(@"<%s:%d> %s, " format, strrchr("/" __FILE__, '/') + 1, __LINE__, __PRETTY_FUNCTION__, ## __VA_ARGS__)
|
||||
#else
|
||||
#define NSLogDebug(format, ...)
|
||||
#endif
|
||||
|
||||
|
||||
#endif
|
||||
+34
-21
@@ -9,8 +9,7 @@
|
||||
#import "PNObjectModel.h"
|
||||
#import "PNObject.h"
|
||||
#import "PEARFileManager.h"
|
||||
|
||||
#define DEF_DOCUMENT_ROOT @"Documents"
|
||||
#import "PNObjectConstants.h"
|
||||
|
||||
@interface PNObjectModel()
|
||||
|
||||
@@ -118,30 +117,44 @@ static bool isFirstAccess = YES;
|
||||
|
||||
if ([[object class] conformsToProtocol:@protocol(PNObjectSubclassing)]) {
|
||||
|
||||
id value;
|
||||
|
||||
SEL selector = NSSelectorFromString(@"getObject");
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
|
||||
[invocation setSelector:selector];
|
||||
[invocation setTarget:value];
|
||||
[invocation invoke];
|
||||
|
||||
NSDictionary *objectDict;
|
||||
[invocation getReturnValue:&objectDict];
|
||||
|
||||
NSLogDebug(@"%@",objectDict);
|
||||
|
||||
NSData *objectData = [NSKeyedArchiver archivedDataWithRootObject:objectDict];
|
||||
|
||||
if ([self issetPNObjectModelForObject:object]) {
|
||||
|
||||
|
||||
id value;
|
||||
|
||||
SEL selector = NSSelectorFromString(@"getObject");
|
||||
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
|
||||
[invocation setSelector:selector];
|
||||
[invocation setTarget:value];
|
||||
[invocation invoke];
|
||||
|
||||
NSDictionary *objectDict;
|
||||
[invocation getReturnValue:&objectDict];
|
||||
|
||||
NSLogDebug(@"%@",objectDict);
|
||||
|
||||
NSData *objectData = [NSKeyedArchiver archivedDataWithRootObject:objectDict];
|
||||
|
||||
[_fileManager updateFileWithData:objectData filePath:[self objectName:object] permisson:@(0755)];
|
||||
if ([_fileManager updateFileWithData:objectData filePath:[self objectName:object] permisson:@(0755)]) {
|
||||
return object;
|
||||
}
|
||||
else {
|
||||
return [NSError errorWithDomain:NSLocalizedString(@"Object cannot be updated", @"") code:kHTTPStatusCodeBadRequest userInfo:nil];
|
||||
}
|
||||
}
|
||||
else {
|
||||
if ([_fileManager createFileWithData:objectData filePath:[self objectName:object] permisson:@(0755)]) {
|
||||
return object;
|
||||
}
|
||||
else {
|
||||
return [NSError errorWithDomain:NSLocalizedString(@"Object cannot be created", @"") code:kHTTPStatusCodeBadRequest userInfo:nil];
|
||||
}
|
||||
}
|
||||
}
|
||||
else {
|
||||
return [NSError errorWithDomain:NSLocalizedString(@"passed object is not conform to protocol PNObjectSubclassing", @"") code:kHTTPStatusCodeBadRequest userInfo:nil];
|
||||
}
|
||||
}
|
||||
else {
|
||||
return [NSError errorWithDomain:NSLocalizedString(@"", @"") code:<#(NSInteger)#> userInfo:<#(nullable NSDictionary *)#>]
|
||||
return [NSError errorWithDomain:NSLocalizedString(@"passed object is not PNObject Subclass", @"") code:kHTTPStatusCodeBadRequest userInfo:nil];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#import "PNObjectProperty.h"
|
||||
#import "objc/runtime.h"
|
||||
#import "PNObjectConstants.h"
|
||||
|
||||
@implementation PNObjectProperty
|
||||
|
||||
|
||||
Reference in new issue
Block a user