diff --git a/Example/PNObject/PNObjectAppDelegate.m b/Example/PNObject/PNObjectAppDelegate.m index a60328a..ea30551 100644 --- a/Example/PNObject/PNObjectAppDelegate.m +++ b/Example/PNObject/PNObjectAppDelegate.m @@ -8,6 +8,7 @@ #import "PNObjectAppDelegate.h" #import "PNObject.h" +#import "PNUser.h" @implementation PNObjectAppDelegate @@ -15,15 +16,21 @@ { // Override point for customization after application launch. /*[PNObjectConfig initSharedInstanceForEnvironments:@{ EnvironmentDevelopment : @"https://development.it/api/v1", - EnvironmentStage : @"https://stage.it/api/v1", - EnvironmentProduction : @"http://pnobjectdemo.giuseppenucifora.com/" - }]; - - [[PNObjectConfig sharedInstance] setEnvironment:Production]; - - - [PNObject get];*/ + EnvironmentStage : @"https://stage.it/api/v1", + EnvironmentProduction : @"http://pnobjectdemo.giuseppenucifora.com/" + }]; + + [[PNObjectConfig sharedInstance] setEnvironment:Production]; + + + [PNObject get];*/ + /*PNUser *user = [PNUser sharedInstance]; + [user setFirstName:@"peppe"]; + [user setLastName:@"nucifora"]; + + NSLog(@"user : %@",[user getObject]); + */ return YES; } diff --git a/Example/PNObject/PNObjectViewController.m b/Example/PNObject/PNObjectViewController.m index 68743bc..650e13e 100644 --- a/Example/PNObject/PNObjectViewController.m +++ b/Example/PNObject/PNObjectViewController.m @@ -7,7 +7,6 @@ // #import "PNObjectViewController.h" -//#import "PNObject.h" @interface PNObjectViewController () diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index a4bc66c..ffbd115 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -1475,14 +1475,14 @@ isa = PBXHeadersBuildPhase; buildActionMask = 2147483647; files = ( - CAC4420D53FB5288CEBCE296412C16CB /* PNAddress.h in Headers */, - EA8E630DD2C78A4A5DC0F8DEF3484D62 /* PNLocation.h in Headers */, 941354E1B678B9221BD1C15EE37BA55E /* PNObject-umbrella.h in Headers */, 295C2B75DF7492F4AF35CDF93891E816 /* PNObject.h in Headers */, - CE706AD64F95B815E15F7154C20C9B8C /* PNObjectConfig.h in Headers */, - 0149AF8689F2AAE11A2E689E6EE912DD /* PNObjectProperty.h in Headers */, 5D8BB0A730FC0A0AE17B84459F953E5F /* PNObjectSubclassing.h in Headers */, + CE706AD64F95B815E15F7154C20C9B8C /* PNObjectConfig.h in Headers */, F6BB55A8386E361E9D22492FB3C2E868 /* PNUser.h in Headers */, + CAC4420D53FB5288CEBCE296412C16CB /* PNAddress.h in Headers */, + EA8E630DD2C78A4A5DC0F8DEF3484D62 /* PNLocation.h in Headers */, + 0149AF8689F2AAE11A2E689E6EE912DD /* PNObjectProperty.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; diff --git a/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/PNObject.xcscheme b/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/PNObject.xcscheme index 093c627..dfb6228 100644 --- a/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/PNObject.xcscheme +++ b/Example/Pods/Pods.xcodeproj/xcshareddata/xcschemes/PNObject.xcscheme @@ -14,7 +14,7 @@ buildForArchiving = "YES"> diff --git a/Pod/Classes/PNObject.h b/Pod/Classes/PNObject.h index 08f5f43..1bc8677 100644 --- a/Pod/Classes/PNObject.h +++ b/Pod/Classes/PNObject.h @@ -15,8 +15,9 @@ @property (nonatomic, strong) NSString *objID; @property (nonatomic, strong) NSDate *createdDate; -@property (nonatomic, strong) NSDictionary *objectMapping; +@property (nonatomic, strong, getter=getObject) NSDictionary *objectMapping; - (instancetype) initWithJSON:(NSDictionary*) JSON; ++ (void) get; @end diff --git a/Pod/Classes/PNObject.m b/Pod/Classes/PNObject.m index 99edcde..ab7e737 100644 --- a/Pod/Classes/PNObject.m +++ b/Pod/Classes/PNObject.m @@ -10,7 +10,7 @@ #import #import #import -#import "User/PNUser.h" +#import "PNObject/PNUser.h" @interface PNObject() @@ -22,6 +22,32 @@ @implementation PNObject + ++ (void) get { + + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; + manager.securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]; + manager.securityPolicy.allowInvalidCertificates = YES; + + [manager GET:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",@"User"] parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) { + + + NSLog(@"JSON: %@", responseObject); + NSLog(@"JSON: %@", [responseObject class]); + + PNUser *user = [[PNUser alloc] initWithJSON:responseObject]; + + NSLog(@"%@",user); + + + } failure:^(NSURLSessionTask *operation, NSError *error) { + + NSLog(@"Error: %@", error); + + }]; +} + + - (instancetype) init { self = [super init]; @@ -123,7 +149,7 @@ else { BOOL isPNObjectSubclass = [NSClassFromString(propertyType) isSubclassOfClass:[PNObject class]]; if(isPNObjectSubclass) { - SEL selector = NSSelectorFromString(@"reverseMapping"); + SEL selector = NSSelectorFromString(@"getObject"); NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: [[PNObject class] instanceMethodSignatureForSelector:selector]]; [invocation setSelector:selector]; @@ -149,6 +175,10 @@ return _JSON; } +- (NSDictionary*) getObject { + return [self reverseMapping]; +} + - (void)populateObjectFromJSON:(id)JSON { diff --git a/Pod/Classes/User/PNAddress.h b/Pod/Classes/User/PNAddress.h index 9599168..b89c742 100644 --- a/Pod/Classes/User/PNAddress.h +++ b/Pod/Classes/User/PNAddress.h @@ -7,7 +7,7 @@ // #import -#import "PNLocation.h" +#import @interface PNAddress : PNObject diff --git a/Pod/Classes/User/PNUser.h b/Pod/Classes/User/PNUser.h index 3b04509..050a16f 100644 --- a/Pod/Classes/User/PNUser.h +++ b/Pod/Classes/User/PNUser.h @@ -2,33 +2,18 @@ // PNUser.h // Pods // -// Created by Giuseppe Nucifora on 08/01/16. +// Created by Giuseppe Nucifora on 15/01/16. // // -#import -#import "PNAddress.h" +#import -@interface PNUser : PNObject +@interface PNUser : NSObject -@property (strong, nonatomic) NSString *userId; -@property (strong, nonatomic) NSString *firstName; -@property (strong, nonatomic) NSString *lastName; -@property (nonatomic, strong) NSString *profileImage; -@property (nonatomic, strong) NSString *sex; -@property (nonatomic, strong) NSDate *birthDate; -@property (nonatomic, strong) NSString *phone; -@property (nonatomic) BOOL hasAcceptedPrivacy; -@property (nonatomic) BOOL hasAcceptedNewsletter; -@property (nonatomic) BOOL hasVerifiedEmail; -@property (nonatomic, strong) NSDate *emailVerifiedDate; -@property (nonatomic, strong) NSString *email; -@property (strong, nonatomic) NSString *username; -@property (nonatomic) BOOL publicProfile; -@property (nonatomic) NSInteger loginCount; -@property (strong, nonatomic) NSDate *createdAt; -@property (nonatomic, strong) NSString *facebookId; -@property (nonatomic, strong) NSString *facebookAccessToken; -@property (nonatomic, strong) PNAddress *address; +/** + * gets singleton object. + * @return singleton + */ ++ (PNUser*)sharedInstance; @end diff --git a/Pod/Classes/User/PNUser.m b/Pod/Classes/User/PNUser.m index d43897d..990e847 100644 --- a/Pod/Classes/User/PNUser.m +++ b/Pod/Classes/User/PNUser.m @@ -2,7 +2,7 @@ // PNUser.m // Pods // -// Created by Giuseppe Nucifora on 08/01/16. +// Created by Giuseppe Nucifora on 15/01/16. // // @@ -10,54 +10,60 @@ @implementation PNUser -/* - @property (strong, nonatomic) NSString *userId; - @property (strong, nonatomic) NSString *firstName; - @property (strong, nonatomic) NSString *lastName; - @property (nonatomic, strong) NSString *profileImage; - @property (nonatomic, strong) NSString *sex; - @property (nonatomic, strong) NSDate *birthDate; - @property (nonatomic, strong) NSString *phone; - @property (nonatomic) BOOL hasAcceptedPrivacy; - @property (nonatomic) BOOL hasAcceptedNewsletter; - @property (nonatomic) BOOL hasVerifiedEmail; - @property (nonatomic, strong) NSDate *emailVerifiedDate; - @property (nonatomic, strong) NSString *email; - @property (strong, nonatomic) NSString *username; - @property (nonatomic) BOOL publicProfile; - @property (nonatomic) NSInteger loginCount; - @property (strong, nonatomic) NSDate *createdAt; - @property (nonatomic, strong) NSString *facebookId; - @property (nonatomic, strong) NSString *facebookAccessToken; - @property (nonatomic, strong) PNAddress *address; - */ +static PNUser *SINGLETON = nil; -+ (NSDictionary *)objcetMapping { - NSDictionary *mapping = @{@"userId":@"id", - @"firstName":@"firstName", - @"lastName":@"lastName", - @"profileImage":@"profileImage", - @"sex":@"sex", - @"birthDate":@"birthDate", - @"phone":@"phone", - @"hasAcceptedPrivacy":@"hasAcceptedPrivacy", - @"hasAcceptedNewsletter":@"hasAcceptedNewsletter", - @"hasVerifiedEmail":@"hasVerifiedEmail", - @"emailVerifiedDate":@"emailVerifiedDate", - @"email":@"email", - @"username":@"username", - @"publicProfile":@"public_profile", - @"loginCount":@"login_count", - @"createdAt":@"created_at", - @"facebookId":@"facebookId", - @"facebookAccessToken":@"facebookAccessToken", - @"address":@{@"key":@"address",@"type":@"PNAddress"} - }; - return mapping; +static bool isFirstAccess = YES; + +#pragma mark - Public Method + ++ (id)sharedInstance +{ + static dispatch_once_t onceToken; + dispatch_once(&onceToken, ^{ + isFirstAccess = NO; + SINGLETON = [[super allocWithZone:NULL] init]; + }); + + return SINGLETON; } -+ (NSString *)objectClassName { - return @"User"; +#pragma mark - Life Cycle + ++ (id) allocWithZone:(NSZone *)zone +{ + return [self sharedInstance]; +} + ++ (id)copyWithZone:(struct _NSZone *)zone +{ + return [self sharedInstance]; +} + ++ (id)mutableCopyWithZone:(struct _NSZone *)zone +{ + return [self sharedInstance]; +} + +- (id)copy +{ + return [[PNUser alloc] init]; +} + +- (id)mutableCopy +{ + return [[PNUser alloc] init]; +} + +- (id) init +{ + if(SINGLETON){ + return SINGLETON; + } + if (isFirstAccess) { + [self doesNotRecognizeSelector:_cmd]; + } + self = [super init]; + return self; }