- Aggiornato readme

This commit is contained in:
Giuseppe Nucifora 2017-01-11 01:14:46 +01:00
parent d6bc683799
commit 866880eaa9
3 changed files with 170 additions and 86 deletions

View File

@ -31,29 +31,16 @@
_window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]]; _window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Override point for customization after application launch. // Override point for customization after application launch.
/*
[PNObjectConfig initSharedInstanceForEnvironments:@{EnvironmentDevelopment : @"http://packman.local/app_dev.php/api/v1/", [PNObjectConfig initSharedInstanceForEnvironments:@{EnvironmentDevelopment : @"http://pnobject.local/api/v1/",
EnvironmentStage : @"https://packman.ppreview.it/app_stage.php/api/v1/", EnvironmentStage : @"http://pnobject.stage.it/api/v1/",
EnvironmentProduction : @"http://packman.ppreview.it/app_stage.php/api/v1/" EnvironmentProduction : @"http://pnobject.prod.it/api/v1/"
} userSubclass:[PNUser class] withOauth:YES]; } userSubclass:[PNUser class] withOauthMode:OAuthModeClientCredential];
[[PNObjectConfig sharedInstance] setHTTPHeaderValue:@"application/x-www-form-urlencoded" forKey:@"Content-Type"];
[[PNObjectConfig sharedInstance] setClientID:@"1_pqjo2w5k7j4g8skco408oc048w8so0ws840gcg8k8gwsgk0g4" clientSecret:@"10w0vg2v6eggooc4wks4w4s0wkwok0wkck0w888so0o80g88w8" forEnv:EnvironmentProduction]; [[PNObjectConfig sharedInstance] setClientID:@"xxxxxxxxx" clientSecret:@"xxxxxxxxxxxx" forEnv:EnvironmentStage];
#ifdef DEBUG [[PNObjectConfig sharedInstance] setClientID:@"xxxxxxxxx" clientSecret:@"xxxxxxxxxxxx" forEnv:EnvironmentProduction];
[[PNObjectConfig sharedInstance] setEnvironment:EnvironmentStage]; [[PNObjectConfig sharedInstance] setEnvironment:EnvironmentStage];
#endif*/
[PNObjectConfig initSharedInstanceForEnvironments:@{EnvironmentDevelopment : @"http://bmwcallingweb.local/app_dev.php/api/v1/",
EnvironmentStage : @"http://bmwcallingweb.ppreview.it/app_dev.php/api/v1/",
EnvironmentProduction : @"http://bmwcallingweb.ppreview.it/app_dev.php/api/v1/"
} userSubclass:[PNUser class] withOauthMode:OAuthModePassword];
[[PNObjectConfig sharedInstance] setClientID:@"1_pqjo2w5k7j4g8skco408oc048w8so0ws840gcg8k8gwsgk0g4" clientSecret:@"10w0vg2v6eggooc4wks4w4s0wkwok0wkck0w888so0o80g88w8" forEnv:EnvironmentStage];
[[PNObjectConfig sharedInstance] setOauthUserName:@"admin" oauthPassword:@"admin" forEnv:EnvironmentStage];
[[PNObjectConfig sharedInstance] setEnvironment:EnvironmentStage];
//[[PNObjectConfig sharedInstance] setHTTPHeaderValue:@"XMLHttpRequest" forKey:@"X-Request-With"]; //[[PNObjectConfig sharedInstance] setHTTPHeaderValue:@"XMLHttpRequest" forKey:@"X-Request-With"];

View File

@ -30,7 +30,7 @@
- (void)viewDidLoad - (void)viewDidLoad
{ {
[super viewDidLoad]; [super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib. // Do any additional setup after loading the view, typically from a nib.
_refreshToken = [UIButton newAutoLayoutView]; _refreshToken = [UIButton newAutoLayoutView];
[_refreshToken addTarget:self action:@selector(refreshTokenAction) forControlEvents:UIControlEventTouchUpInside]; [_refreshToken addTarget:self action:@selector(refreshTokenAction) forControlEvents:UIControlEventTouchUpInside];
@ -102,72 +102,22 @@
- (void) apiCallAction { - (void) apiCallAction {
/*PNObjcPassword *password = [PNObjcPassword new]; PNObjcPassword *password = [PNObjcPassword new];
[password setPassword:@"asdasdasd"]; [password setPassword:@"asdasdasd"];
[password setConfirmPassword:@"asdasdasd"]; [password setConfirmPassword:@"asdasdasd"];
User *user = [User new]; PNUser *user = [PNUser new];
[user setFirstName:@"Giuseppe"]; [user setFirstName:@"Test"];
[user setLastName:@"Nuficora"]; [user setLastName:@"Test"];
[user setEmail:@"packman5@giuseppenucifora.com"]; [user setEmail:@"pnobject@pnobject.com"];
[user setPassword:password]; [user setPassword:password];
[user setHasAcceptedNewsletter:YES]; [user setHasAcceptedNewsletter:YES];
[user setHasAcceptedPrivacy:YES]; [user setHasAcceptedPrivacy:YES];
*/
//[user saveLocally]; [user saveLocally];
NSLog(@"%@",[[PNUser currentUser] JSONFormObject]); NSLog(@"%@",[[PNUser currentUser] JSONFormObject]);
//NSLog(@"%@",[user JSONObjectMap]);
/*[user registerWithBlockSuccess:^(PNUser * _Nullable responseObject) {
} failure:^(NSError * _Nonnull error) {
}];*/
/*[[User currentUser] socialLoginWithBlockSuccessFromViewController:self
blockSuccess:^(PNUser * _Nullable responseObject) {
} failure:^(NSError * _Nonnull error) {
}];*/
//User * user = [User currentUser];
//if ([user isAuthenticated]) {
/*[User loginCurrentUserWithEmail:@"demo@packman.example" password:@"demo@packman.example" withBlockSuccess:^(PNUser * _Nullable responseObject) {
NSLog(@"response : %@",responseObject);
NSLog(@"%@",[User currentUser]);
} failure:^(NSError * _Nonnull error) {
NSLog(@"response : %@",error);
}];*/
/*[PNUser socialLoginWithBlockSuccess:^(PNUser * _Nullable responseObject) {
} failure:^(NSError * _Nonnull error) {
}];*/
/*[PNUser socialUserFromViewController:self blockSuccess:^(PNUser * _Nullable responseObject) {
NSLog(@"%@",[[PNUser currentUser] JSONFormObject]);
} failure:^(NSError * _Nonnull error) {
}];*/
/*[User resetPasswordForEmail:@"packman@giuseppenucifora.com" Progress:^(NSProgress * _Nonnull uploadProgress) {
} Success:^(NSDictionary * _Nullable responseObject) {
} failure:^(NSError * _Nonnull error) {
}];*/
} }

147
README.md
View File

@ -20,6 +20,153 @@ it, simply add the following line to your Podfile:
pod "PNObject" pod "PNObject"
``` ```
Configure PNObject endpoint client ID, client secret and OAuthModePassword
###
```
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[PNObjectConfig initSharedInstanceForEnvironments:@{EnvironmentDevelopment : @"http://pnobject.local/api/v1/",
EnvironmentStage : @"http://pnobject.stage.it/api/v1/",
EnvironmentProduction : @"http://pnobject.prod.it/api/v1/"
} userSubclass:[PNUser class] withOauthMode:OAuthModePassword];
[[PNObjectConfig sharedInstance] setClientID:@"xxxxxxxxx" clientSecret:@"xxxxxxxxxxxx" forEnv:EnvironmentStage];
[[PNObjectConfig sharedInstance] setClientID:@"xxxxxxxxx" clientSecret:@"xxxxxxxxxxxx" forEnv:EnvironmentProduction];
[[PNObjectConfig sharedInstance] setOauthUserName:@"admin" oauthPassword:@"admin" forEnv:EnvironmentStage];
[[PNObjectConfig sharedInstance] setEnvironment:EnvironmentStage];
}
```
###
Configure PNObject endpoint client ID, client secret and OAuthModeClientCredential
---
```
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[PNObjectConfig initSharedInstanceForEnvironments:@{EnvironmentDevelopment : @"http://pnobject.local/api/v1/",
EnvironmentStage : @"http://pnobject.stage.it/api/v1/",
EnvironmentProduction : @"http://pnobject.prod.it/api/v1/"
} userSubclass:[PNUser class] withOauthMode:OAuthModeClientCredential];
[[PNObjectConfig sharedInstance] setClientID:@"xxxxxxxxx" clientSecret:@"xxxxxxxxxxxx" forEnv:EnvironmentStage];
[[PNObjectConfig sharedInstance] setClientID:@"xxxxxxxxx" clientSecret:@"xxxxxxxxxxxx" forEnv:EnvironmentProduction];
[[PNObjectConfig sharedInstance] setEnvironment:EnvironmentStage];
}
```
###
Configure PNObject endpoint and using custom PNUser object
---
```
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
[PNObjectConfig initSharedInstanceForEnvironments:@{EnvironmentDevelopment : @"http://pnobject.local/api/v1/",
EnvironmentStage : @"http://pnobject.stage.it/api/v1/",
EnvironmentProduction : @"http://pnobject.prod.it/api/v1/"
} userSubclass:[PNUser class] withOauthMode:OAuthModeClientCredential];
[[PNObjectConfig sharedInstance] setClientID:@"xxxxxxxxx" clientSecret:@"xxxxxxxxxxxx" forEnv:EnvironmentStage];
[[PNObjectConfig sharedInstance] setClientID:@"xxxxxxxxx" clientSecret:@"xxxxxxxxxxxx" forEnv:EnvironmentProduction];
[[PNObjectConfig sharedInstance] setEnvironment:EnvironmentStage];
}
```
###
User.h
---
```
#import <PNObject/PNUser.h>
@interface User : PNUser
@end
```
###
User.m
---
```
#import "User.h"
#import "PNObject+Protected.h"
#import "PNObject+PNObjectConnection.h"
#import <NSDate_Utils/NSDate+NSDate_Util.h>
@interface User () <PNObjectSubclassing>
@end
@implementation User
+ (NSDictionary *)objcetMapping {
NSMutableDictionary *userMapping = [[NSMutableDictionary alloc] initWithDictionary:[[PNUser class] objcetMapping]];
return userMapping;
}
+ (BOOL) singleInstance {
return [[self class] singleInstance];
}
+ (NSString * _Nonnull) objectEndPoint {
return @"User";
}
+ (NSString * _Nonnull ) objectClassName {
return @"User";
}
###
Custom Reset Password
+ (void) resetPasswordForEmail:(NSString * _Nonnull) userEmail
Progress:(nullable void (^)(NSProgress * _Nonnull uploadProgress)) uploadProgress
Success:(nullable void (^)(NSDictionary * _Nullable responseObject))success
failure:(nullable void (^)(NSError * _Nonnull error))failure {
[self POSTWithEndpointAction:@"password-reset-request"
parameters:[self resetPasswordFormObject:userEmail]
progress:uploadProgress
success:^(NSURLSessionDataTask * _Nullable task, NSDictionary * _Nullable responseObject) {
if (success) {
success(responseObject);
}
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
if (failure) {
failure(error);
}
}];
}
+ (NSDictionary * _Nonnull) resetPasswordFormObject:(NSString *) email {
NSMutableDictionary *resetPasswordDictionary = [[NSMutableDictionary alloc] init];
[resetPasswordDictionary setObject:email forKey:@"email"];
return resetPasswordDictionary;
}
```
## Author ## Author
Giuseppe Nucifora, me@giuseppenucifora.com Giuseppe Nucifora, me@giuseppenucifora.com