- Fix vari
This commit is contained in:
1 parent
c3e77e7a09
commit
e2e17186ac
30 files changed
+1254
-873
No files matched your search
@@ -10,7 +10,8 @@
|
||||
#import "PNObjectSubclassing.h"
|
||||
#import "PNObjectConfig.h"
|
||||
|
||||
@interface PNObject : NSObject <PNObjectSubclassing>
|
||||
|
||||
@interface PNObject : NSObject
|
||||
|
||||
@property (nonatomic, strong) NSString *objID;
|
||||
@property (nonatomic, strong) NSDate *createdDate;
|
||||
@@ -18,6 +19,5 @@
|
||||
|
||||
- (instancetype) initWithJSON:(NSDictionary*) JSON;
|
||||
|
||||
|
||||
|
||||
+ (void) get;
|
||||
@end
|
||||
+38
-15
@@ -10,6 +10,7 @@
|
||||
#import <PNObjectProperty.h>
|
||||
#import <NSDate_Utils/NSDate+NSDate_Util.h>
|
||||
#import <AFNetworking/AFNetworking.h>
|
||||
#import "User/PNUser.h"
|
||||
|
||||
@interface PNObject()
|
||||
|
||||
@@ -21,12 +22,43 @@
|
||||
|
||||
@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];
|
||||
|
||||
if (self) {
|
||||
|
||||
|
||||
if ([[self class] isSubclassOfClass:[PNObject class]]) {
|
||||
NSAssert([[self class] conformsToProtocol:@protocol(PNObjectSubclassing)], @"Subclass object must conform to PNObjectSubclassing");
|
||||
|
||||
_objectMapping = [[self class] objcetMapping];
|
||||
|
||||
NSAssert(_objectMapping, @"You must create objectMapping");
|
||||
}
|
||||
}
|
||||
return self;
|
||||
}
|
||||
@@ -34,6 +66,7 @@
|
||||
- (instancetype) initWithJSON:(NSDictionary*) JSON {
|
||||
self = [self init];
|
||||
if (self) {
|
||||
|
||||
NSAssert(_objectMapping, @"You must create objectMapping");
|
||||
_JSON = [[NSDictionary alloc] initWithDictionary:JSON];
|
||||
|
||||
@@ -179,8 +212,6 @@
|
||||
continue;
|
||||
}
|
||||
|
||||
//NSLog(@"Looking for : %@ -- %@ -- %@", propertyType, mappedJSONKey, value);
|
||||
|
||||
|
||||
((void (^)())@{
|
||||
@"c" : ^{
|
||||
@@ -217,7 +248,7 @@
|
||||
},
|
||||
@"NSDate" : ^{
|
||||
NSString *str = [NSString stringWithFormat:@"%@", value];
|
||||
NSDate *val = [NSDate dateFromString:str];
|
||||
NSDate *val = [[NSDate dateFromString:str withFormat:kNSDateHelperFormatSQLDateWithTime] toLocalTime];
|
||||
[self setValue:val forKey:propertyName];
|
||||
},
|
||||
@"NSArray" : ^{
|
||||
@@ -253,16 +284,8 @@
|
||||
|
||||
}
|
||||
|
||||
#pragma mark PNObjectSubclassing
|
||||
|
||||
+ (NSString *) objectClassName {
|
||||
|
||||
- (NSString*) description {
|
||||
return [_JSON description];
|
||||
}
|
||||
|
||||
+ (NSDictionary *) objcetMapping {
|
||||
|
||||
}
|
||||
|
||||
#pragma mark -
|
||||
|
||||
@end
|
||||
@@ -26,6 +26,8 @@ extern NSString* const EnvironmentDevelopment;
|
||||
* gets singleton object.
|
||||
* @return singleton
|
||||
*/
|
||||
+ (instancetype) sharedInstance;
|
||||
|
||||
/**
|
||||
*
|
||||
*
|
||||
@@ -38,10 +40,10 @@ extern NSString* const EnvironmentDevelopment;
|
||||
*
|
||||
* @return singleton
|
||||
*/
|
||||
+ (instancetype) sharedInstanceForEnvironments:(NSDictionary *) endpointUrlsForEnvironments;
|
||||
|
||||
- (void) enableEnvironment:(Environment) env;
|
||||
+ (instancetype) initSharedInstanceForEnvironments:(NSDictionary *) endpointUrlsForEnvironments;
|
||||
|
||||
- (void) setEnvironment:(Environment) env;
|
||||
|
||||
- (NSString *) PNObjEndpoint;
|
||||
|
||||
@end
|
||||
@@ -16,10 +16,12 @@ NSString* const EnvironmentDevelopment = @"PNObjectConfigDevelopment";
|
||||
@interface PNObjectConfig()
|
||||
|
||||
@property (nonatomic, strong) NSMutableDictionary *configuration;
|
||||
@property (nonatomic, strong) NSString *currentEnvironment;
|
||||
@property (nonatomic) BOOL devEnabled;
|
||||
@property (nonatomic) BOOL stageEnabled;
|
||||
@property (nonatomic) BOOL productionEnabled;
|
||||
|
||||
|
||||
@end
|
||||
|
||||
@implementation PNObjectConfig
|
||||
@@ -32,7 +34,7 @@ static bool isFirstAccess = YES;
|
||||
|
||||
#pragma mark - Public Method
|
||||
|
||||
+ (id)sharedInstance
|
||||
+ (instancetype)sharedInstance
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
@@ -45,7 +47,7 @@ static bool isFirstAccess = YES;
|
||||
|
||||
#pragma mark - Life Cycle
|
||||
|
||||
+ (instancetype) sharedInstanceForEnvironments:(NSDictionary *) endpointUrlsForEnvironments {
|
||||
+ (instancetype) initSharedInstanceForEnvironments:(NSDictionary *) endpointUrlsForEnvironments {
|
||||
SINGLETON = [self sharedInstance];
|
||||
|
||||
if (SINGLETON) {
|
||||
@@ -55,7 +57,7 @@ static bool isFirstAccess = YES;
|
||||
EnvironmentDevelopment : ^{
|
||||
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
|
||||
if (endpointUrl) {
|
||||
[SINGLETON.configuration setValue:endpointUrl forKey:key];
|
||||
[SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key];
|
||||
SINGLETON.devEnabled = YES;
|
||||
}
|
||||
|
||||
@@ -63,14 +65,14 @@ static bool isFirstAccess = YES;
|
||||
EnvironmentStage : ^{
|
||||
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
|
||||
if (endpointUrl) {
|
||||
[SINGLETON.configuration setValue:endpointUrl forKey:key];
|
||||
[SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key];
|
||||
SINGLETON.stageEnabled = YES;
|
||||
}
|
||||
},
|
||||
EnvironmentProduction : ^{
|
||||
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
|
||||
if (endpointUrl) {
|
||||
[SINGLETON.configuration setValue:endpointUrl forKey:key];
|
||||
[SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key];
|
||||
SINGLETON.productionEnabled = YES;
|
||||
}
|
||||
}
|
||||
@@ -79,8 +81,8 @@ static bool isFirstAccess = YES;
|
||||
})();
|
||||
}
|
||||
NSAssert(SINGLETON.productionEnabled, @"EnvironmentProduction must be valid endpoint url");
|
||||
SINGLETON.currentEnvironment = [[SINGLETON configuration] objectForKey:EnvironmentProduction];
|
||||
|
||||
NSLog(@"Config : %@",SINGLETON.configuration);
|
||||
}
|
||||
return SINGLETON;
|
||||
}
|
||||
@@ -126,21 +128,37 @@ static bool isFirstAccess = YES;
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void) enableEnvironment:(Environment) env {
|
||||
- (void) setEnvironment:(Environment) env {
|
||||
|
||||
_currentEnvironment = nil;
|
||||
|
||||
switch (env) {
|
||||
case Development:{
|
||||
|
||||
if (_devEnabled) {
|
||||
_currentEnvironment = [_configuration objectForKey:EnvironmentDevelopment];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Stage:{
|
||||
|
||||
if (_stageEnabled) {
|
||||
_currentEnvironment = [_configuration objectForKey:EnvironmentStage];
|
||||
}
|
||||
}
|
||||
break;
|
||||
case Production:
|
||||
default:
|
||||
if (_productionEnabled) {
|
||||
_currentEnvironment = [_configuration objectForKey:EnvironmentProduction];
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
NSAssert(_currentEnvironment,@"Selected environment generate error. Please check configuration");
|
||||
|
||||
}
|
||||
|
||||
- (NSString *) PNObjEndpoint {
|
||||
return _currentEnvironment;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,23 @@
|
||||
//
|
||||
// PNAddress.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 13/01/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import <PNObject/PNObject.h>
|
||||
#import "PNLocation.h"
|
||||
|
||||
@interface PNAddress : PNObject <PNObjectSubclassing>
|
||||
|
||||
@property (nonatomic, strong) NSString *country;
|
||||
@property (nonatomic, strong) NSString *province;
|
||||
@property (nonatomic, strong) NSString *city;
|
||||
@property (nonatomic, strong) NSString *street;
|
||||
@property (nonatomic, strong) NSNumber *number;
|
||||
@property (nonatomic, strong) NSString *zip;
|
||||
@property (nonatomic, strong) NSString *istruction;
|
||||
@property (nonatomic, strong) PNLocation *location;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,29 @@
|
||||
//
|
||||
// PNAddress.m
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 13/01/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import "PNAddress.h"
|
||||
|
||||
@implementation PNAddress
|
||||
|
||||
+ (NSString *) objectClassName {
|
||||
return @"Address";
|
||||
}
|
||||
|
||||
+ (NSDictionary *) objcetMapping {
|
||||
NSDictionary *mapping = @{@"country":@"country",
|
||||
@"province":@"province",
|
||||
@"city":@"city",
|
||||
@"street":@"street",
|
||||
@"number":@"number",
|
||||
@"zip":@"zip",
|
||||
@"location":@{@"key":@"location",@"type":@"PNLocation"},
|
||||
};
|
||||
return mapping;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,16 @@
|
||||
//
|
||||
// PNLocation.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 13/01/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import <PNObject/PNObject.h>
|
||||
|
||||
@interface PNLocation : PNObject <PNObjectSubclassing>
|
||||
|
||||
@property (nonatomic) CGFloat lat;
|
||||
@property (nonatomic) CGFloat lng;
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,25 @@
|
||||
//
|
||||
// PNLocation.m
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 13/01/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import "PNLocation.h"
|
||||
|
||||
@implementation PNLocation
|
||||
|
||||
+ (NSString *) objectClassName {
|
||||
return @"Location";
|
||||
}
|
||||
|
||||
|
||||
+ (NSDictionary *) objcetMapping {
|
||||
NSDictionary *mapping = @{@"lat":@"lat",
|
||||
@"lng":@"lng",
|
||||
};
|
||||
return mapping;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,36 @@
|
||||
//
|
||||
// PNUser.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 08/01/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import <PNObject/PNObject.h>
|
||||
#import "PNAddress.h"
|
||||
|
||||
@interface PNUser : PNObject <PNObjectSubclassing>
|
||||
|
||||
@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;
|
||||
|
||||
|
||||
|
||||
@end
|
||||
@@ -0,0 +1,64 @@
|
||||
//
|
||||
// PNUser.m
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 08/01/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import "PNUser.h"
|
||||
|
||||
@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;
|
||||
*/
|
||||
|
||||
+ (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;
|
||||
}
|
||||
|
||||
+ (NSString *)objectClassName {
|
||||
return @"User";
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -1,13 +0,0 @@
|
||||
//
|
||||
// User.h
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 08/01/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import <PNObject/PNObject.h>
|
||||
|
||||
@interface User : PNObject
|
||||
|
||||
@end
|
||||
@@ -1,22 +0,0 @@
|
||||
//
|
||||
// User.m
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 08/01/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import "User.h"
|
||||
|
||||
@implementation User
|
||||
|
||||
- (instancetype) initWithJSON:(NSDictionary *)JSON {
|
||||
|
||||
self = [super initWithJSON:JSON];
|
||||
if (self) {
|
||||
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user