- Add PNObject connections
This commit is contained in:
1 parent
0de3997a2a
commit
f569c8545c
8 files changed
+133
-24
No files matched your search
@@ -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
|
||||
@@ -0,0 +1,101 @@
|
||||
//
|
||||
// PNObjectConnection.m
|
||||
// Pods
|
||||
//
|
||||
// Created by Giuseppe Nucifora on 18/01/16.
|
||||
//
|
||||
//
|
||||
|
||||
#import "PNObject+PNObjectConnection.h"
|
||||
#import "PNObjectConstants.h"
|
||||
#import <NSDate_Utils/NSDate+NSDate_Util.h>
|
||||
#import "PNObjectConfig.h"
|
||||
#import "PNObjectModel.h"
|
||||
#import <AFNetworking/AFNetworking.h>
|
||||
#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<AFMultipartFormData> _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
|
||||
@@ -37,6 +37,4 @@
|
||||
|
||||
- (void) saveLocallyInBackGroundWithBlock:(id _Nonnull) object inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id _Nullable responseObject, NSError * _Nullable error)) responseBlock;
|
||||
|
||||
+ (void) get;
|
||||
|
||||
@end
|
||||
+1
-20
@@ -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];
|
||||
|
||||
@@ -48,6 +48,6 @@ extern NSString* const EnvironmentDevelopment;
|
||||
|
||||
- (NSString *) PNObjEndpoint;
|
||||
|
||||
- (NSString *) minPasswordLenght:(NSUInteger) passLenght;
|
||||
- (void) setAcceptablePasswordLenght:(NSUInteger) passLenght;
|
||||
|
||||
@end
|
||||
@@ -165,4 +165,8 @@ static bool isFirstAccess = YES;
|
||||
return _currentEnvironment;
|
||||
}
|
||||
|
||||
- (void) setAcceptablePasswordLenght:(NSUInteger) passLenght {
|
||||
_minPasswordLenght = passLenght;
|
||||
}
|
||||
|
||||
@end
|
||||
@@ -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;
|
||||
|
||||
Reference in new issue
Block a user