Merge branch 'develop' into 'master'

Develop

- Release 0.2.4

See merge request !9
This commit is contained in:
Giuseppe Nucifora 2016-02-03 01:22:57 +00:00
commit 7c7a56147d
21 changed files with 953 additions and 760 deletions

View File

@ -71,7 +71,44 @@
ReferencedContainer = "container:PNObject.xcodeproj"> ReferencedContainer = "container:PNObject.xcodeproj">
</BuildableReference> </BuildableReference>
</BuildableProductRunnable> </BuildableProductRunnable>
<EnvironmentVariables>
<EnvironmentVariable
key = "NSZombieEnabled"
value = "YES"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "NSAutoreleaseFreedObjectCheckEnabled"
value = "YES"
isEnabled = "YES">
</EnvironmentVariable>
<EnvironmentVariable
key = "NSDebugEnabled"
value = "YES"
isEnabled = "YES">
</EnvironmentVariable>
</EnvironmentVariables>
<AdditionalOptions> <AdditionalOptions>
<AdditionalOption
key = "DYLD_INSERT_LIBRARIES"
value = "/usr/lib/libgmalloc.dylib"
isEnabled = "YES">
</AdditionalOption>
<AdditionalOption
key = "NSZombieEnabled"
value = "YES"
isEnabled = "YES">
</AdditionalOption>
<AdditionalOption
key = "MallocGuardEdges"
value = ""
isEnabled = "YES">
</AdditionalOption>
<AdditionalOption
key = "MallocScribble"
value = ""
isEnabled = "YES">
</AdditionalOption>
</AdditionalOptions> </AdditionalOptions>
</LaunchAction> </LaunchAction>
<ProfileAction <ProfileAction

View File

@ -18,40 +18,61 @@
// Override point for customization after application launch. // Override point for customization after application launch.
[PNObjectConfig initSharedInstanceForEnvironments:@{ EnvironmentDevelopment : @"https://development.it/api/v1", [PNObjectConfig initSharedInstanceForEnvironments:@{ EnvironmentDevelopment : @"https://development.it/api/v1",
EnvironmentStage : @"https://stage.it/api/v1", EnvironmentStage : @"https://stage.it/api/v1",
EnvironmentProduction : @"http://pnobjectdemo.giuseppenucifora.com/" EnvironmentProduction : @"https://pnobject.giuseppenucifora.com/"
}]; }];
[[PNObjectConfig sharedInstance] setEnvironment:Production]; [[PNObjectConfig sharedInstance] setEnvironment:Production];
[[[PNObjectConfig sharedInstance] manager] setSecurityPolicy:[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]]; //[[[PNObjectConfig sharedInstance] manager] setSecurityPolicy:[AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]];
[[PNObjectConfig sharedInstance] manager].securityPolicy.allowInvalidCertificates = YES; //[[PNObjectConfig sharedInstance] manager].securityPolicy.allowInvalidCertificates = YES;
//[PNObject get];*/ //[PNObject get];*/
/*
PNUser *user = [PNUser currentUser];
PNUser *user = [PNUser currentUser]; //NSLog(@"user : %@",[user getJSONObject]);
//NSLog(@"user : %@",[user getJSONObject]); //[user autoRemoveLocally];
[user setFirstName:@"Giuseppe2"];
//[user autoRemoveLocally]; [user setLastName:@"Nucifora2"];
[user setFirstName:@"Giuseppe2"]; [user setEmail:@"giuseppe.nucifora@giuseppenucifora.com"];
[user setLastName:@"Nucifora2"]; [user setSex:@"M"];
[user setEmail:@"giuseppe.nucifora@giuseppenucifora.com"]; [user setHasAcceptedNewsletter:NO];
[user setSex:@"M"]; [user setHasAcceptedPrivacy:YES];
[user setHasAcceptedNewsletter:NO]; [user setUsername:@"giuseppe.nucifora"];
[user setHasAcceptedPrivacy:YES]; [user setPassword:@"giuseppe.nucifora.password"];
[user setUsername:@"giuseppe.nucifora"]; [user setPhone:@"+393485904995"];
[user setPassword:@"giuseppe.nucifora.password"]; [user setUserId:@"blablabla"];
[user setPhone:@"+393485904995"]; [user saveLocally];
[user setUserId:@"blablabla"];
[user saveLocally];
[user setFirstName:@"Angela"]; [user setFirstName:@"Angela"];
[user setLastName:@"Sapienza"]; [user setLastName:@"Sapienza"];
[user getJSONObject]; [user getJSONObject];*/
NSLog(@"%@",[PNUser PNObjClassName]); PNAccessToken *accessToken = [PNAccessToken currentAccessToken];
NSLog(@"%@",[accessToken JSONObject]);
/*[[[PNObjectConfig sharedInstance] manager] GET:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingString:[PNAccessToken PNObjClassName]] parameters:nil progress:^(NSProgress * _Nonnull downloadProgress) {
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
PNAccessToken *accessToken = [[PNAccessToken alloc] initWithJSON:responseObject];
NSLog(@"%@",[accessToken JSONObject]);
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[accessToken saveLocally];
});
//[accessToken saveLocally];
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
NSLog(@"%@",error);
}];*/
//NSLog(@"%@",userDictionary); //NSLog(@"%@",userDictionary);
/* /*

View File

@ -11,7 +11,7 @@
int main(int argc, char * argv[]) int main(int argc, char * argv[])
{ {
@autoreleasepool { @autoreleasepool {
return UIApplicationMain(argc, argv, nil, NSStringFromClass([PNObjectAppDelegate class])); return UIApplicationMain(argc, argv, nil, NSStringFromClass([PNObjectAppDelegate class]));
} }
} }

View File

@ -28,7 +28,7 @@ PODS:
- NSString-Helper (1.0.2) - NSString-Helper (1.0.2)
- nv-ios-http-status (0.0.1) - nv-ios-http-status (0.0.1)
- PEAR-FileManager-iOS (1.3.1) - PEAR-FileManager-iOS (1.3.1)
- PNObject (0.1.0): - PNObject (0.2.3):
- AFNetworking - AFNetworking
- CodFis-Helper - CodFis-Helper
- NSDate_Utils - NSDate_Utils
@ -69,7 +69,7 @@ SPEC CHECKSUMS:
NSString-Helper: 0ee74919829a332f9838fa87b28cb2d1d991e92c NSString-Helper: 0ee74919829a332f9838fa87b28cb2d1d991e92c
nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f
PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3 PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3
PNObject: b71ba455c15aedd1233cdf02bcf65d348d96da72 PNObject: 7bd9bb008740ecb0d8e5a8ab58606a4eb4d10132
Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2 Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2
StrongestPasswordValidator: 554de9038705e18904f0337903dfd3b85a6b271b StrongestPasswordValidator: 554de9038705e18904f0337903dfd3b85a6b271b
UIDevice-Utils: 0beb5f9d2bd256a3efe05c1e43a2a8b8702199c4 UIDevice-Utils: 0beb5f9d2bd256a3efe05c1e43a2a8b8702199c4

View File

@ -1,7 +1,7 @@
{ {
"name": "PNObject", "name": "PNObject",
"version": "0.1.0", "version": "0.2.3",
"summary": "PNObject.", "summary": "PNObject is a simple replica of the more complex ParseObject",
"homepage": "https://github.com/giuseppenucifora/PNObject", "homepage": "https://github.com/giuseppenucifora/PNObject",
"license": "MIT", "license": "MIT",
"authors": { "authors": {
@ -9,7 +9,7 @@
}, },
"source": { "source": {
"git": "https://github.com/giuseppenucifora/PNObject.git", "git": "https://github.com/giuseppenucifora/PNObject.git",
"tag": "0.1.0" "tag": "0.2.3"
}, },
"platforms": { "platforms": {
"ios": "7.0" "ios": "7.0"

View File

@ -28,7 +28,7 @@ PODS:
- NSString-Helper (1.0.2) - NSString-Helper (1.0.2)
- nv-ios-http-status (0.0.1) - nv-ios-http-status (0.0.1)
- PEAR-FileManager-iOS (1.3.1) - PEAR-FileManager-iOS (1.3.1)
- PNObject (0.1.0): - PNObject (0.2.3):
- AFNetworking - AFNetworking
- CodFis-Helper - CodFis-Helper
- NSDate_Utils - NSDate_Utils
@ -69,7 +69,7 @@ SPEC CHECKSUMS:
NSString-Helper: 0ee74919829a332f9838fa87b28cb2d1d991e92c NSString-Helper: 0ee74919829a332f9838fa87b28cb2d1d991e92c
nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f nv-ios-http-status: b6c2b5fc8656cc19e0d3000dadce2080b99d0e2f
PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3 PEAR-FileManager-iOS: 3bc403f68a53483f5629aa822f4649e40275c4d3
PNObject: b71ba455c15aedd1233cdf02bcf65d348d96da72 PNObject: 7bd9bb008740ecb0d8e5a8ab58606a4eb4d10132
Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2 Specta: ac94d110b865115fe60ff2c6d7281053c6f8e8a2
StrongestPasswordValidator: 554de9038705e18904f0337903dfd3b85a6b271b StrongestPasswordValidator: 554de9038705e18904f0337903dfd3b85a6b271b
UIDevice-Utils: 0beb5f9d2bd256a3efe05c1e43a2a8b8702199c4 UIDevice-Utils: 0beb5f9d2bd256a3efe05c1e43a2a8b8702199c4

File diff suppressed because it is too large Load Diff

View File

@ -14,7 +14,7 @@
buildForArchiving = "YES"> buildForArchiving = "YES">
<BuildableReference <BuildableReference
BuildableIdentifier = 'primary' BuildableIdentifier = 'primary'
BlueprintIdentifier = '4FB4437C636DCECA1396EC4C' BlueprintIdentifier = 'E35BB1A0261F32B3489855CF'
BlueprintName = 'PNObject' BlueprintName = 'PNObject'
ReferencedContainer = 'container:Pods.xcodeproj' ReferencedContainer = 'container:Pods.xcodeproj'
BuildableName = 'PNObject.framework'> BuildableName = 'PNObject.framework'>

View File

@ -15,7 +15,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>FMWK</string> <string>FMWK</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.1.0</string> <string>0.2.3</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>

View File

@ -1,15 +1,16 @@
#import <UIKit/UIKit.h> #import <UIKit/UIKit.h>
#import "PNAccessToken.h"
#import "PNAddress.h"
#import "PNInstallation.h"
#import "PNLocation.h"
#import "PNUser.h"
#import "PNObject+PNObjectConnection.h" #import "PNObject+PNObjectConnection.h"
#import "PNObject+Protected.h" #import "PNObject+Protected.h"
#import "PNObject.h" #import "PNObject.h"
#import "PNObjectConfig.h" #import "PNObjectConfig.h"
#import "PNObjectConstants.h" #import "PNObjectConstants.h"
#import "PNObjectModel.h" #import "PNObjectModel.h"
#import "PNObjectProperty.h"
#import "PNAddress.h"
#import "PNLocation.h"
#import "PNUser.h"
FOUNDATION_EXPORT double PNObjectVersionNumber; FOUNDATION_EXPORT double PNObjectVersionNumber;
FOUNDATION_EXPORT const unsigned char PNObjectVersionString[]; FOUNDATION_EXPORT const unsigned char PNObjectVersionString[];

View File

@ -13,7 +13,7 @@
<key>CFBundlePackageType</key> <key>CFBundlePackageType</key>
<string>BNDL</string> <string>BNDL</string>
<key>CFBundleShortVersionString</key> <key>CFBundleShortVersionString</key>
<string>0.1.0</string> <string>0.2.3</string>
<key>CFBundleSignature</key> <key>CFBundleSignature</key>
<string>????</string> <string>????</string>
<key>CFBundleVersion</key> <key>CFBundleVersion</key>

View File

@ -8,7 +8,7 @@
Pod::Spec.new do |s| Pod::Spec.new do |s|
s.name = "PNObject" s.name = "PNObject"
s.version = "0.2.3" s.version = "0.2.4"
s.summary = "PNObject is a simple replica of the more complex ParseObject" s.summary = "PNObject is a simple replica of the more complex ParseObject"
# This description is used to generate tags and improve search results. # This description is used to generate tags and improve search results.

View File

@ -6,7 +6,7 @@
// //
// //
#import <PNObject/PNObject.h> #import "PNObject.h"
@interface PNAccessToken : PNObject @interface PNAccessToken : PNObject
@ -14,6 +14,27 @@ typedef NS_ENUM(NSInteger, TokenType) {
TokenTypeBasic = 1, TokenTypeBasic = 1,
TokenTypeBearer = 2 TokenTypeBearer = 2
}; };
/**
* gets singleton object of current user session.
*
* @return singleton
*/
+ (instancetype _Nonnull) currentAccessToken;
/**
* gets singleton object of current user session.
*
* @return singleton
*/
+ (instancetype _Nonnull) currentAccessTokenWithJSON:(NSDictionary *)JSON;
///--------------------------------------
#pragma mark - PNAccessToken Properties
///--------------------------------------
/** /**
* <#Description#> * <#Description#>
*/ */
@ -22,9 +43,18 @@ typedef NS_ENUM(NSInteger, TokenType) {
* <#Description#> * <#Description#>
*/ */
@property (nonatomic, strong, nullable) NSDate *expirationDate; @property (nonatomic, strong, nullable) NSDate *expirationDate;
@property (nonatomic, strong, nullable) NSNumber *expiresIn;
/** /**
* <#Description#> * <#Description#>
*/ */
@property (nonatomic) TokenType tokenType; @property (nonatomic) TokenType tokenType;
@property (nonatomic, strong, nullable) NSString *tokenTypeString;
@property (nonatomic, strong, nullable) NSString *scope;
@property (nonatomic, strong, nullable) NSString *refreshToken;
@end @end

View File

@ -7,6 +7,7 @@
// //
#import "PNAccessToken.h" #import "PNAccessToken.h"
#import <NSDate_Utils/NSDate+NSDate_Util.h>
@interface PNAccessToken() <PNObjectSubclassing> @interface PNAccessToken() <PNObjectSubclassing>
@ -14,18 +15,99 @@
@implementation PNAccessToken @implementation PNAccessToken
static PNAccessToken *SINGLETON = nil;
static bool isFirstAccess = YES;
#pragma mark - Public Method
+ (instancetype) currentAccessToken {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] initForCurrentAccessTokenWithJSON:nil];
});
return SINGLETON;
}
+ (instancetype _Nonnull) currentAccessTokenWithJSON:(NSDictionary *)JSON {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] initForCurrentAccessTokenWithJSON:JSON];
});
return SINGLETON;
}
- (instancetype) initForCurrentAccessTokenWithJSON:(NSDictionary *)JSON {
if(SINGLETON){
return SINGLETON;
}
if (isFirstAccess) {
[self doesNotRecognizeSelector:_cmd];
}
NSDictionary *savedAccessToken;
if (JSON) {
savedAccessToken = JSON;
}
else {
savedAccessToken = [[PNObjectModel sharedInstance] fetchObjectsWithClass:[self class]];
}
if (savedAccessToken) {
self = [super initWithJSON:savedAccessToken];
}
else {
self = [super init];
}
if (self) {
if (_tokenTypeString) {
((void (^)())@{
@"beaer" : ^{
_tokenType = TokenTypeBearer;
},
@"basic" : ^{
_tokenType = TokenTypeBasic;
}
}[_tokenTypeString] ?: ^{
})();
}
if (_expiresIn) {
_expirationDate = [[NSDate date] dateByAddingHours:[_expiresIn integerValue]];
}
}
return self;
}
#pragma mark PNObjectSubclassing Protocol #pragma mark PNObjectSubclassing Protocol
+ (NSDictionary *)objcetMapping { + (NSDictionary *)objcetMapping {
NSDictionary *mapping = @{ NSDictionary *mapping = @{
@"accessToken":@"accessToken", @"accessToken":@"access_token",
@"expirationDate":@"expirationDate", @"expiresIn":@"expires_in",
@"tokenType":@"tokenType", @"tokenTypeString":@"token_type",
@"tokenType":@"scope",
@"refreshToken":@"refresh_token",
}; };
return mapping; return mapping;
} }
- (instancetype) initWithJSON:(NSDictionary *)JSON {
return [[self class] currentAccessTokenWithJSON:JSON];
}
+ (NSString *)objectClassName { + (NSString *)objectClassName {
return @"AccessToken"; return @"AccessToken";
} }
@ -38,7 +120,4 @@
@end @end

View File

@ -7,7 +7,7 @@
// //
#import "PNObject.h" #import "PNObject.h"
#import "PNAccessToken.h"
@interface PNUser : PNObject @interface PNUser : PNObject
@ -33,7 +33,7 @@
//- (void) setPassword:(NSString * _Nonnull)password inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id responseObject, NSError * error)) responseBlock; //- (void) setPassword:(NSString * _Nonnull)password inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id responseObject, NSError * error)) responseBlock;
///-------------------------------------- ///--------------------------------------
#pragma mark - PNLocation Properties #pragma mark - PNUser Properties
///-------------------------------------- ///--------------------------------------
/** /**

View File

@ -19,79 +19,79 @@
- (NSURLSessionDataTask * _Nonnull)GETWithProgress:(void (^ _Nullable)(NSProgress * _Nonnull))downloadProgress - (NSURLSessionDataTask * _Nonnull)GETWithProgress:(void (^ _Nullable)(NSProgress * _Nonnull))downloadProgress
success:(void (^ _Nullable)(NSURLSessionDataTask * _Nonnull, id _Nullable))success success:(void (^ _Nullable)(NSURLSessionDataTask * _Nonnull, id _Nullable))success
failure:(void (^ _Nullable)(NSURLSessionDataTask * _Nullable, NSError * _Nonnull))failure { failure:(void (^ _Nullable)(NSURLSessionDataTask * _Nullable, NSError * _Nonnull))failure {
return [[[PNObjectConfig sharedInstance] manager] GET:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",[[self class] objectClassName]] parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) { return [[[PNObjectConfig sharedInstance] manager] GET:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",[[self class] objectClassName]] parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSLogDebug(@"JSON: %@", responseObject); NSLogDebug(@"JSON: %@", responseObject);
NSLogDebug(@"JSON: %@", [responseObject class]); NSLogDebug(@"JSON: %@", [responseObject class]);
self.JSON = [[NSDictionary alloc] initWithDictionary:responseObject]; self.JSON = [[NSDictionary alloc] initWithDictionary:responseObject];
[self populateObjectFromJSON:responseObject]; [self populateObjectFromJSON:responseObject];
} failure:^(NSURLSessionTask *operation, NSError *error) { } failure:^(NSURLSessionTask *operation, NSError *error) {
NSLogDebug(@"Error: %@", error); NSLogDebug(@"Error: %@", error);
}]; }];
} }
- (NSURLSessionDataTask *)POSTWithProgress:(nullable void (^)(NSProgress * _Nonnull)) uploadProgress - (NSURLSessionDataTask *)POSTWithProgress:(nullable void (^)(NSProgress * _Nonnull)) uploadProgress
success:(void (^)(NSURLSessionDataTask *task, id responseObject))success success:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure { failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure {
return [[[PNObjectConfig sharedInstance] manager] POST:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",[[self class] objectClassName]] return [[[PNObjectConfig sharedInstance] manager] POST:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",[[self class] objectClassName]]
parameters:[self getJSONObject] constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) { parameters:[self JSONObject] constructingBodyWithBlock:^(id<AFMultipartFormData> _Nonnull formData) {
} progress:^(NSProgress * _Nonnull _uploadProgress) { } progress:^(NSProgress * _Nonnull _uploadProgress) {
if (uploadProgress) { if (uploadProgress) {
uploadProgress(_uploadProgress); uploadProgress(_uploadProgress);
} }
} success:^(NSURLSessionDataTask * _Nonnull _task, id _Nullable _responseObject) { } success:^(NSURLSessionDataTask * _Nonnull _task, id _Nullable _responseObject) {
if (success) { if (success) {
success(_task,_responseObject); success(_task,_responseObject);
} }
} failure:^(NSURLSessionDataTask * _Nullable _task, NSError * _Nonnull _error) { } failure:^(NSURLSessionDataTask * _Nullable _task, NSError * _Nonnull _error) {
if (failure) { if (failure) {
failure(_task,_error); failure(_task,_error);
} }
}]; }];
} }
- (NSURLSessionDataTask *)PUTWithSuccess:(void (^)(NSURLSessionDataTask *task, id responseObject))success - (NSURLSessionDataTask *)PUTWithSuccess:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure { failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure {
return [[[PNObjectConfig sharedInstance] manager] PUT:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",[[self class] objectClassName]] return [[[PNObjectConfig sharedInstance] manager] PUT:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",[[self class] objectClassName]]
parameters:[self getJSONObject] parameters:[self JSONObject]
success:^(NSURLSessionDataTask * _Nonnull _task, id _Nullable _responseObject) { success:^(NSURLSessionDataTask * _Nonnull _task, id _Nullable _responseObject) {
if (success) { if (success) {
success(_task,_responseObject); success(_task,_responseObject);
} }
} failure:^(NSURLSessionDataTask * _Nullable _task, NSError * _Nonnull _error) { } failure:^(NSURLSessionDataTask * _Nullable _task, NSError * _Nonnull _error) {
if (failure) { if (failure) {
failure(_task,_error); failure(_task,_error);
} }
}]; }];
} }
- (NSURLSessionDataTask *)DELETEWithSuccess:(void (^)(NSURLSessionDataTask *task, id responseObject))success - (NSURLSessionDataTask *)DELETEWithSuccess:(void (^)(NSURLSessionDataTask *task, id responseObject))success
failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure { failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure {
return [[[PNObjectConfig sharedInstance] manager] DELETE:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",[[self class] objectClassName]] return [[[PNObjectConfig sharedInstance] manager] DELETE:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",[[self class] objectClassName]]
parameters:[self getJSONObject] parameters:[self JSONObject]
success:^(NSURLSessionDataTask * _Nonnull _task, id _Nullable _responseObject) { success:^(NSURLSessionDataTask * _Nonnull _task, id _Nullable _responseObject) {
if (success) { if (success) {
success(_task,_responseObject); success(_task,_responseObject);
} }
} failure:^(NSURLSessionDataTask * _Nullable _task, NSError * _Nonnull _error) { } failure:^(NSURLSessionDataTask * _Nullable _task, NSError * _Nonnull _error) {
if (failure) { if (failure) {
failure(_task,_error); failure(_task,_error);
} }
}]; }];
} }
@end @end

View File

@ -27,6 +27,9 @@
NSDictionary *properties = [PNObject propertiesForClass:self.class]; NSDictionary *properties = [PNObject propertiesForClass:self.class];
for (NSString *propertyName in properties) { for (NSString *propertyName in properties) {
if ([propertyName isEqualToString:@"description"] || [propertyName isEqualToString:@"debugDescription"]) {
continue;
}
[self addObserver:self forKeyPath:propertyName options:NSKeyValueObservingOptionNew context:nil]; [self addObserver:self forKeyPath:propertyName options:NSKeyValueObservingOptionNew context:nil];
} }
@ -39,8 +42,11 @@
NSString *mappedJSONType; NSString *mappedJSONType;
NSString *propertyType = [properties valueForKey:propertyName]; NSString *propertyType = [properties valueForKey:propertyName];
NSLogDebug(@"%@",self.JSONObject);
id mappingValue = [self.objectMapping valueForKey:propertyName]; NSLogDebug(@"%@",[[self class] objcetMapping]);
id mappingValue = [[[self class] objcetMapping] valueForKey:propertyName];
if([mappingValue isKindOfClass:NSDictionary.class]) { if([mappingValue isKindOfClass:NSDictionary.class]) {
mappedJSONKey = [mappingValue valueForKey:@"key"]; mappedJSONKey = [mappingValue valueForKey:@"key"];
@ -55,7 +61,7 @@
} }
// Get JSON value for the mapped key // Get JSON value for the mapped key
id value = [JSON valueForKeyPath:propertyName]; id value = [JSON valueForKeyPath:mappedJSONKey];
((void (^)())@{ ((void (^)())@{
@ -150,7 +156,7 @@
NSString *propertyType = [properties valueForKey:propertyName]; NSString *propertyType = [properties valueForKey:propertyName];
id mappingValue = [self.objectMapping valueForKey:propertyName]; id mappingValue = [self.JSONObject valueForKey:propertyName];
if([mappingValue isKindOfClass:NSDictionary.class]) { if([mappingValue isKindOfClass:NSDictionary.class]) {
mappedJSONKey = [mappingValue valueForKey:@"key"]; mappedJSONKey = [mappingValue valueForKey:@"key"];

View File

@ -50,7 +50,7 @@
/** /**
* <#Description#> * <#Description#>
*/ */
@property (nonatomic, strong, getter=getJSONObject, nonnull) NSDictionary * objectMapping; @property (nonatomic, strong, nonnull) NSDictionary * JSONObject;
@end @end

View File

@ -75,9 +75,9 @@
NSMutableDictionary * objectDict = [[NSMutableDictionary alloc] initWithDictionary:[[self class] objcetMapping]]; NSMutableDictionary * objectDict = [[NSMutableDictionary alloc] initWithDictionary:[[self class] objcetMapping]];
[objectDict addEntriesFromDictionary:[PNObject objcetMapping]]; [objectDict addEntriesFromDictionary:[PNObject objcetMapping]];
_objectMapping = objectDict; _JSONObject = objectDict;
NSAssert(_objectMapping, @"You must create objectMapping"); NSAssert(_JSONObject, @"You must create objectMapping");
_singleInstance = [[self class] singleInstance]; _singleInstance = [[self class] singleInstance];
@ -102,9 +102,9 @@
NSMutableDictionary * objectDict = [[NSMutableDictionary alloc] initWithDictionary:[[self class] objcetMapping]]; NSMutableDictionary * objectDict = [[NSMutableDictionary alloc] initWithDictionary:[[self class] objcetMapping]];
[objectDict addEntriesFromDictionary:[PNObject objcetMapping]]; [objectDict addEntriesFromDictionary:[PNObject objcetMapping]];
_objectMapping = objectDict; _JSONObject = objectDict;
NSAssert(_objectMapping, @"You must create objectMapping"); NSAssert(_JSONObject, @"You must create objectMapping");
_singleInstance = [[self class] singleInstance]; _singleInstance = [[self class] singleInstance];
@ -112,7 +112,7 @@
} }
NSAssert(_objectMapping, @"You must create objectMapping"); NSAssert(_JSONObject, @"You must create objectMapping");
_JSON = [[NSMutableDictionary alloc] initWithDictionary:JSON]; _JSON = [[NSMutableDictionary alloc] initWithDictionary:JSON];
[self populateObjectFromJSON:_JSON]; [self populateObjectFromJSON:_JSON];
@ -129,8 +129,8 @@
NSDictionary *properties = [PNObject propertiesForClass:self.class]; NSDictionary *properties = [PNObject propertiesForClass:self.class];
for (NSString* propertyName in _objectMapping) { for (NSString* propertyName in _JSONObject) {
id mappingValue = [_objectMapping objectForKey:propertyName]; id mappingValue = [_JSONObject objectForKey:propertyName];
if([mappingValue isKindOfClass:NSDictionary.class]) { if([mappingValue isKindOfClass:NSDictionary.class]) {
mappedJSONKey = [mappingValue valueForKey:@"key"]; mappedJSONKey = [mappingValue valueForKey:@"key"];
@ -205,7 +205,7 @@
@"NSArray" : ^{ @"NSArray" : ^{
NSMutableArray *arr = [NSMutableArray array]; NSMutableArray *arr = [NSMutableArray array];
for(id PNObject in value) { for(id PNObject in value) {
SEL selector = NSSelectorFromString(@"getJSONObject"); SEL selector = NSSelectorFromString(@"JSONObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: [[PNObject class] instanceMethodSignatureForSelector:selector]]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature: [[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector]; [invocation setSelector:selector];
[invocation setTarget:PNObject]; [invocation setTarget:PNObject];
@ -224,7 +224,7 @@
PNObject *val = [[NSClassFromString(mappedJSONType) alloc] initWithJSON:JSONObject]; PNObject *val = [[NSClassFromString(mappedJSONType) alloc] initWithJSON:JSONObject];
[arr addObject:val]; [arr addObject:val];
SEL selector = NSSelectorFromString(@"getJSONObject"); SEL selector = NSSelectorFromString(@"JSONObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector]; [invocation setSelector:selector];
[invocation setTarget:value]; [invocation setTarget:value];
@ -238,7 +238,7 @@
}[propertyType] ?: ^{ }[propertyType] ?: ^{
BOOL isPNObjectSubclass = [NSClassFromString(propertyType) isSubclassOfClass:[PNObject class]]; BOOL isPNObjectSubclass = [NSClassFromString(propertyType) isSubclassOfClass:[PNObject class]];
if(isPNObjectSubclass) { if(isPNObjectSubclass) {
SEL selector = NSSelectorFromString(@"getJSONObject"); SEL selector = NSSelectorFromString(@"JSONObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector]; [invocation setSelector:selector];
[invocation setTarget:value]; [invocation setTarget:value];
@ -259,7 +259,8 @@
return _JSON; return _JSON;
} }
- (NSDictionary* _Nonnull) getJSONObject {
- (NSDictionary* _Nonnull) JSONObject {
if (!_JSON) { if (!_JSON) {
return [self reverseMapping]; return [self reverseMapping];
} }
@ -307,7 +308,9 @@
- (id _Nonnull) saveLocally { - (id _Nonnull) saveLocally {
return [_objectModel saveLocally:self]; __weak id weakSelf = self;
return [_objectModel saveLocally:weakSelf];
} }
- (BOOL) autoRemoveLocally { - (BOOL) autoRemoveLocally {
@ -318,20 +321,34 @@
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
{ {
[_JSON setObject:[change objectForKey:@"new"] forKey:keyPath]; [_JSON setObject:[change objectForKey:@"new"] forKey:[[[self class] objcetMapping] objectForKey:keyPath]];
} }
/*- (void)dealloc - (void)dealloc
{ {
NSDictionary *properties = [PNObject propertiesForClass:self.class]; NSDictionary *properties = [PNObject propertiesForClass:self.class];
for (NSString *propertyName in properties) { for (NSString *propertyName in properties) {
if ([[PNObject protectedProperties] containsObject:propertyName]) { if ([propertyName isEqualToString:@"description"] || [propertyName isEqualToString:@"debugDescription"]) {
continue; continue;
} }
[self removeObserver:self forKeyPath:propertyName];
@try {
[self removeObserver:self forKeyPath:propertyName];
}
@catch (NSException *exception) {
}
@finally {
}
} }
} _JSON = nil;
*/ _JSONObject = nil;
_objID = nil;
_createdAt = nil;
}
@end @end

View File

@ -39,134 +39,136 @@ static bool isFirstAccess = YES;
+ (instancetype)sharedInstance + (instancetype)sharedInstance
{ {
static dispatch_once_t onceToken; static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{ dispatch_once(&onceToken, ^{
isFirstAccess = NO; isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] init]; SINGLETON = [[super allocWithZone:NULL] init];
}); });
return SINGLETON; return SINGLETON;
} }
#pragma mark - Life Cycle #pragma mark - Life Cycle
+ (instancetype) initSharedInstanceForEnvironments:(NSDictionary *) endpointUrlsForEnvironments { + (instancetype) initSharedInstanceForEnvironments:(NSDictionary *) endpointUrlsForEnvironments {
SINGLETON = [self sharedInstance]; SINGLETON = [self sharedInstance];
if (SINGLETON) { if (SINGLETON) {
for (NSString *key in [endpointUrlsForEnvironments allKeys]) { for (NSString *key in [endpointUrlsForEnvironments allKeys]) {
((void (^)())@{ ((void (^)())@{
EnvironmentDevelopment : ^{ EnvironmentDevelopment : ^{
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]]; NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
if (endpointUrl) { if (endpointUrl) {
[SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key]; [SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key];
SINGLETON.devEnabled = YES; SINGLETON.devEnabled = YES;
} }
}, },
EnvironmentStage : ^{ EnvironmentStage : ^{
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]]; NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
if (endpointUrl) { if (endpointUrl) {
[SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key]; [SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key];
SINGLETON.stageEnabled = YES; SINGLETON.stageEnabled = YES;
} }
}, },
EnvironmentProduction : ^{ EnvironmentProduction : ^{
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]]; NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
if (endpointUrl) { if (endpointUrl) {
[SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key]; [SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key];
SINGLETON.productionEnabled = YES; SINGLETON.productionEnabled = YES;
} }
} }
}[key] ?: ^{ }[key] ?: ^{
})(); })();
} }
NSAssert(SINGLETON.productionEnabled, @"EnvironmentProduction must be valid endpoint url"); NSAssert(SINGLETON.productionEnabled, @"EnvironmentProduction must be valid endpoint url");
SINGLETON.currentEnvironment = [[SINGLETON configuration] objectForKey:EnvironmentProduction]; SINGLETON.currentEnvironment = [[SINGLETON configuration] objectForKey:EnvironmentProduction];
} }
return SINGLETON; return SINGLETON;
} }
+ (id) allocWithZone:(NSZone *)zone + (id) allocWithZone:(NSZone *)zone
{ {
return [self sharedInstance]; return [self sharedInstance];
} }
+ (id)copyWithZone:(struct _NSZone *)zone + (id)copyWithZone:(struct _NSZone *)zone
{ {
return [self sharedInstance]; return [self sharedInstance];
} }
+ (id)mutableCopyWithZone:(struct _NSZone *)zone + (id)mutableCopyWithZone:(struct _NSZone *)zone
{ {
return [self sharedInstance]; return [self sharedInstance];
} }
- (id)copy - (id)copy
{ {
return [[PNObjectConfig alloc] init]; return [[PNObjectConfig alloc] init];
} }
- (id)mutableCopy - (id)mutableCopy
{ {
return [[PNObjectConfig alloc] init]; return [[PNObjectConfig alloc] init];
} }
- (id) init - (id) init
{ {
if(SINGLETON){ if(SINGLETON){
return SINGLETON; return SINGLETON;
} }
if (isFirstAccess) { if (isFirstAccess) {
[self doesNotRecognizeSelector:_cmd]; [self doesNotRecognizeSelector:_cmd];
} }
self = [super init]; self = [super init];
if (self) { if (self) {
_configuration = [[NSMutableDictionary alloc] init]; _configuration = [[NSMutableDictionary alloc] init];
_minPasswordLenght = minPassLenght; _minPasswordLenght = minPassLenght;
}
return self; _manager = [AFHTTPSessionManager manager];
}
return self;
} }
- (void) setEnvironment:(Environment) env { - (void) setEnvironment:(Environment) env {
_currentEnvironment = nil; _currentEnvironment = nil;
switch (env) { switch (env) {
case Development:{ case Development:{
if (_devEnabled) { if (_devEnabled) {
_currentEnvironment = [_configuration objectForKey:EnvironmentDevelopment]; _currentEnvironment = [_configuration objectForKey:EnvironmentDevelopment];
} }
} }
break; break;
case Stage:{ case Stage:{
if (_stageEnabled) { if (_stageEnabled) {
_currentEnvironment = [_configuration objectForKey:EnvironmentStage]; _currentEnvironment = [_configuration objectForKey:EnvironmentStage];
} }
} }
break; break;
case Production: case Production:
default: default:
if (_productionEnabled) { if (_productionEnabled) {
_currentEnvironment = [_configuration objectForKey:EnvironmentProduction]; _currentEnvironment = [_configuration objectForKey:EnvironmentProduction];
} }
break; break;
} }
NSAssert(_currentEnvironment,@"Selected environment generate error. Please check configuration"); NSAssert(_currentEnvironment,@"Selected environment generate error. Please check configuration");
} }
- (NSString *) PNObjEndpoint { - (NSString *) PNObjEndpoint {
return _currentEnvironment; return _currentEnvironment;
} }
- (void) setAcceptablePasswordLenght:(NSUInteger) passLenght { - (void) setAcceptablePasswordLenght:(NSUInteger) passLenght {
_minPasswordLenght = passLenght; _minPasswordLenght = passLenght;
} }
@end @end

View File

@ -161,7 +161,7 @@ static bool isFirstAccess = YES;
if ([(PNObject*) object singleInstance]) { if ([(PNObject*) object singleInstance]) {
SEL selector = NSSelectorFromString(@"getJSONObject"); SEL selector = NSSelectorFromString(@"JSONObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector]; [invocation setSelector:selector];
[invocation setTarget:object]; [invocation setTarget:object];
@ -197,7 +197,7 @@ static bool isFirstAccess = YES;
NSMutableArray *objects = [[NSMutableArray alloc] initWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:data]]; NSMutableArray *objects = [[NSMutableArray alloc] initWithArray:[NSKeyedUnarchiver unarchiveObjectWithData:data]];
SEL selector = NSSelectorFromString(@"getJSONObject"); SEL selector = NSSelectorFromString(@"JSONObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector]; [invocation setSelector:selector];
[invocation setTarget:object]; [invocation setTarget:object];
@ -225,7 +225,7 @@ static bool isFirstAccess = YES;
NSMutableArray *objects = [[NSMutableArray alloc] init]; NSMutableArray *objects = [[NSMutableArray alloc] init];
SEL selector = NSSelectorFromString(@"getJSONObject"); SEL selector = NSSelectorFromString(@"JSONObject");
NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]]; NSInvocation *invocation = [NSInvocation invocationWithMethodSignature:[[PNObject class] instanceMethodSignatureForSelector:selector]];
[invocation setSelector:selector]; [invocation setSelector:selector];
[invocation setTarget:object]; [invocation setTarget:object];