diff --git a/Example/Pods/Pods.xcodeproj/project.pbxproj b/Example/Pods/Pods.xcodeproj/project.pbxproj index 8b637c4..703ba34 100644 --- a/Example/Pods/Pods.xcodeproj/project.pbxproj +++ b/Example/Pods/Pods.xcodeproj/project.pbxproj @@ -120,6 +120,8 @@ 67459AD239EF669A365519E06B45DCFE /* EXPExpect.h in Headers */ = {isa = PBXBuildFile; fileRef = DC6CFAF47DD5EAA5D62AA2F4660BF69B /* EXPExpect.h */; settings = {ATTRIBUTES = (Public, ); }; }; 68152D921ABF6A423C192C04FDF94F0F /* AFNetworkReachabilityManager.h in Headers */ = {isa = PBXBuildFile; fileRef = C311DF9B86CD8FC191B34A8700A4A8B1 /* AFNetworkReachabilityManager.h */; settings = {ATTRIBUTES = (Public, ); }; }; 6846FE181C4AB07F00FD46A7 /* StrongestPasswordValidator.framework in Frameworks */ = {isa = PBXBuildFile; fileRef = 49943A31C882E74BEEC30F6068C1CB3B /* StrongestPasswordValidator.framework */; }; + 684A5F371C4D350F0035D354 /* PNObject+PNObjectConnection.h in Headers */ = {isa = PBXBuildFile; fileRef = 684A5F351C4D350F0035D354 /* PNObject+PNObjectConnection.h */; }; + 684A5F381C4D350F0035D354 /* PNObject+PNObjectConnection.m in Sources */ = {isa = PBXBuildFile; fileRef = 684A5F361C4D350F0035D354 /* PNObject+PNObjectConnection.m */; }; 68A38977EBAE334DC3C22386D00D2622 /* AFNetworkReachabilityManager.m in Sources */ = {isa = PBXBuildFile; fileRef = 45970A12B4B6EADF2C4F30D8DD555942 /* AFNetworkReachabilityManager.m */; }; 6E1D978790705E137FDE439AA68DD3AA /* EXPFloatTuple.h in Headers */ = {isa = PBXBuildFile; fileRef = 9C7F7D98F2EBB8A63EC1D00F426373D6 /* EXPFloatTuple.h */; settings = {ATTRIBUTES = (Public, ); }; }; 6ED4ABEE8A5F51F5ECB59FA1781D29C6 /* UIActivityIndicatorView+AFNetworking.m in Sources */ = {isa = PBXBuildFile; fileRef = 4FB2C9B0DA395FD916D3B395CBA7CED7 /* UIActivityIndicatorView+AFNetworking.m */; }; @@ -643,6 +645,8 @@ 66C8B02C4B4D7F89FDFD569187797016 /* SPTTestSuite.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SPTTestSuite.m; path = Specta/Specta/SPTTestSuite.m; sourceTree = ""; }; 66EF034BB9EC4B36DA83F1F484FC0780 /* EXPMatchers+beInTheRangeOf.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = "EXPMatchers+beInTheRangeOf.m"; path = "Expecta/Matchers/EXPMatchers+beInTheRangeOf.m"; sourceTree = ""; }; 681E7ACB247E65B384C7F6F20A16C3BB /* SPTExampleGroup.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = SPTExampleGroup.m; path = Specta/Specta/SPTExampleGroup.m; sourceTree = ""; }; + 684A5F351C4D350F0035D354 /* PNObject+PNObjectConnection.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = "PNObject+PNObjectConnection.h"; sourceTree = ""; }; + 684A5F361C4D350F0035D354 /* PNObject+PNObjectConnection.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = "PNObject+PNObjectConnection.m"; sourceTree = ""; }; 6922AB8ABF38E31420E0AD20364FA8F1 /* UIImage+Compare.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = "UIImage+Compare.h"; path = "FBSnapshotTestCase/Categories/UIImage+Compare.h"; sourceTree = ""; }; 6B3DFAF22932E7E8494A97A36DC2FC68 /* ResponseConstants.h */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.h; name = ResponseConstants.h; path = "CodFis-Helper/ResponseConstants.h"; sourceTree = ""; }; 6BABE32DD14BA4EADAAFB828CB0956A2 /* PEARFileManager.m */ = {isa = PBXFileReference; includeInIndex = 1; lastKnownFileType = sourcecode.c.objc; name = PEARFileManager.m; path = "PEAR-FileManager-iOS/PEARFileManager.m"; sourceTree = ""; }; @@ -1168,6 +1172,8 @@ FD4E57DB13C5672E15EB7F469BDB9DFD /* PNObjectModel.m */, CE5C1965380CF58C74C49FE3E5075401 /* PNObjectProperty.h */, 6297F47751BF4100D3E64F1075BB4203 /* PNObjectProperty.m */, + 684A5F351C4D350F0035D354 /* PNObject+PNObjectConnection.h */, + 684A5F361C4D350F0035D354 /* PNObject+PNObjectConnection.m */, 4009CEE68682448A34EE75AEACD49007 /* User */, ); path = Classes; @@ -1757,6 +1763,7 @@ 0831C0CB976355B0E74A993C04F493E8 /* PNObjectModel.h in Headers */, 1864DC2900E321CE616E26077F743039 /* PNObjectProperty.h in Headers */, DC5EBE9BD7C435BBEA8C904795FA7836 /* PNUser.h in Headers */, + 684A5F371C4D350F0035D354 /* PNObject+PNObjectConnection.h in Headers */, ); runOnlyForDeploymentPostprocessing = 0; }; @@ -2573,6 +2580,7 @@ C0245B133AF1089E0ACB376A3332BE10 /* PNObject-dummy.m in Sources */, F298445E53A11D3328468937273A3140 /* PNObject.m in Sources */, 8E968A78142375A5388B57ACE0FF7B26 /* PNObjectConfig.m in Sources */, + 684A5F381C4D350F0035D354 /* PNObject+PNObjectConnection.m in Sources */, 305963E67941479B42F316AE8680E52A /* PNObjectModel.m in Sources */, 46490DD49E86060184B0F31BA8734528 /* PNObjectProperty.m in Sources */, 50FBDCA27970E16B1AAE2352B631BEA1 /* PNUser.m in Sources */, diff --git a/Pod/Classes/PNObject+PNObjectConnection.h b/Pod/Classes/PNObject+PNObjectConnection.h new file mode 100644 index 0000000..487c52d --- /dev/null +++ b/Pod/Classes/PNObject+PNObjectConnection.h @@ -0,0 +1,17 @@ +// +// PNObjectConnection.h +// Pods +// +// Created by Giuseppe Nucifora on 18/01/16. +// +// + +#import "PNObject.h" + +@interface PNObject (PNObjectConnection) + +- (NSURLSessionDataTask * _Nonnull)GETWithProgress:(void (^ _Nullable)(NSProgress * _Nonnull))downloadProgress + success:(void (^ _Nullable)(NSURLSessionDataTask * _Nonnull, id _Nullable))success + failure:(void (^ _Nullable)(NSURLSessionDataTask * _Nullable, NSError * _Nonnull))failure; + +@end diff --git a/Pod/Classes/PNObject+PNObjectConnection.m b/Pod/Classes/PNObject+PNObjectConnection.m new file mode 100644 index 0000000..7601ada --- /dev/null +++ b/Pod/Classes/PNObject+PNObjectConnection.m @@ -0,0 +1,101 @@ +// +// PNObjectConnection.m +// Pods +// +// Created by Giuseppe Nucifora on 18/01/16. +// +// + +#import "PNObject+PNObjectConnection.h" +#import "PNObjectConstants.h" +#import +#import "PNObjectConfig.h" +#import "PNObjectModel.h" +#import +#import "PNObject.m" + +@implementation PNObject (PNObjectConnection) + + + +- (NSURLSessionDataTask * _Nonnull)GETWithProgress:(void (^ _Nullable)(NSProgress * _Nonnull))downloadProgress + success:(void (^ _Nullable)(NSURLSessionDataTask * _Nonnull, id _Nullable))success + 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) { + + + NSLogDebug(@"JSON: %@", responseObject); + NSLogDebug(@"JSON: %@", [responseObject class]); + + _JSON = [[NSDictionary alloc] initWithDictionary:responseObject]; + + [self populateObjectFromJSON:responseObject]; + + + } failure:^(NSURLSessionTask *operation, NSError *error) { + + NSLogDebug(@"Error: %@", error); + + }]; + + + + +} + + +- (NSURLSessionDataTask *)POSTWithProgress:(nullable void (^)(NSProgress * _Nonnull)) uploadProgress + success:(void (^)(NSURLSessionDataTask *task, id responseObject))success + failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure { + + return [[[PNObjectConfig sharedInstance] manager] POST:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",[[self class] objectClassName]] + parameters:[self getObject] constructingBodyWithBlock:^(id _Nonnull formData) { + + } progress:^(NSProgress * _Nonnull _uploadProgress) { + if (uploadProgress) { + uploadProgress(_uploadProgress); + } + } success:^(NSURLSessionDataTask * _Nonnull _task, id _Nullable _responseObject) { + if (success) { + success(_task,_responseObject); + } + } failure:^(NSURLSessionDataTask * _Nullable _task, NSError * _Nonnull _error) { + if (failure) { + failure(_task,_error); + } + }]; +} + +- (NSURLSessionDataTask *)PUTWithSuccess:(void (^)(NSURLSessionDataTask *task, id responseObject))success + failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure { + + return [[[PNObjectConfig sharedInstance] manager] PUT:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",[[self class] objectClassName]] + parameters:[self getObject] + success:^(NSURLSessionDataTask * _Nonnull _task, id _Nullable _responseObject) { + if (success) { + success(_task,_responseObject); + } + } failure:^(NSURLSessionDataTask * _Nullable _task, NSError * _Nonnull _error) { + if (failure) { + failure(_task,_error); + } + }]; +} + +- (NSURLSessionDataTask *)DELETEWithSuccess:(void (^)(NSURLSessionDataTask *task, id responseObject))success + failure:(void (^)(NSURLSessionDataTask *task, NSError *error))failure { + return [[[PNObjectConfig sharedInstance] manager] DELETE:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",[[self class] objectClassName]] + parameters:[self getObject] + success:^(NSURLSessionDataTask * _Nonnull _task, id _Nullable _responseObject) { + if (success) { + success(_task,_responseObject); + } + } failure:^(NSURLSessionDataTask * _Nullable _task, NSError * _Nonnull _error) { + if (failure) { + failure(_task,_error); + } + }]; +} + +@end diff --git a/Pod/Classes/PNObject.h b/Pod/Classes/PNObject.h index 93ff77e..d1a5d9e 100644 --- a/Pod/Classes/PNObject.h +++ b/Pod/Classes/PNObject.h @@ -37,6 +37,4 @@ - (void) saveLocallyInBackGroundWithBlock:(id _Nonnull) object inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id _Nullable responseObject, NSError * _Nullable error)) responseBlock; -+ (void) get; - @end diff --git a/Pod/Classes/PNObject.m b/Pod/Classes/PNObject.m index 0f1783b..0f95c99 100644 --- a/Pod/Classes/PNObject.m +++ b/Pod/Classes/PNObject.m @@ -13,6 +13,7 @@ #import "PNObject/PNUser.h" #import "PNObjectConstants.h" + #define PNOBJECT_DIR @"PNObjects" @@ -30,26 +31,6 @@ @implementation PNObject -+ (void) get { - - [[[PNObjectConfig sharedInstance] manager] GET:[[[PNObjectConfig sharedInstance] PNObjEndpoint] stringByAppendingFormat:@"%@",@"User"] parameters:nil progress:nil success:^(NSURLSessionTask *task, id responseObject) { - - - NSLogDebug(@"JSON: %@", responseObject); - NSLogDebug(@"JSON: %@", [responseObject class]); - - PNUser *user = [[PNUser alloc] initWithJSON:responseObject]; - - NSLogDebug(@"%@",user); - - - } failure:^(NSURLSessionTask *operation, NSError *error) { - - NSLogDebug(@"Error: %@", error); - - }]; -} - - (instancetype) init { self = [super init]; diff --git a/Pod/Classes/PNObjectConfig.h b/Pod/Classes/PNObjectConfig.h index fdbc8cd..d7fcf66 100644 --- a/Pod/Classes/PNObjectConfig.h +++ b/Pod/Classes/PNObjectConfig.h @@ -48,6 +48,6 @@ extern NSString* const EnvironmentDevelopment; - (NSString *) PNObjEndpoint; -- (NSString *) minPasswordLenght:(NSUInteger) passLenght; +- (void) setAcceptablePasswordLenght:(NSUInteger) passLenght; @end \ No newline at end of file diff --git a/Pod/Classes/PNObjectConfig.m b/Pod/Classes/PNObjectConfig.m index fe138b2..76722c6 100644 --- a/Pod/Classes/PNObjectConfig.m +++ b/Pod/Classes/PNObjectConfig.m @@ -165,4 +165,8 @@ static bool isFirstAccess = YES; return _currentEnvironment; } +- (void) setAcceptablePasswordLenght:(NSUInteger) passLenght { + _minPasswordLenght = passLenght; +} + @end diff --git a/Pod/Classes/User/PNUser.h b/Pod/Classes/User/PNUser.h index 28cb748..2fab478 100644 --- a/Pod/Classes/User/PNUser.h +++ b/Pod/Classes/User/PNUser.h @@ -14,7 +14,7 @@ @property (strong, nonatomic) NSString * _Nonnull userId; @property (strong, nonatomic) NSString * _Nonnull firstName; @property (strong, nonatomic) NSString * _Nonnull lastName; -@property (nonatomic, strong) NSString * _Nullable profileImage; +@property (nonatomic, strong) UIImage * _Nullable profileImage; @property (nonatomic, strong) NSString * _Nullable sex; @property (nonatomic, strong) NSDate * _Nullable birthDate; @property (nonatomic, strong) NSString * _Nullable phone;