- Fix vari
This commit is contained in:
1 parent
07ae0d3b42
commit
41c856b3c9
18 files changed
+794
-681
No files matched your search
@@ -6,7 +6,7 @@
|
||||
//
|
||||
//
|
||||
|
||||
#import <PNObject/PNObject.h>
|
||||
#import "PNObject.h"
|
||||
|
||||
@interface PNAccessToken : PNObject
|
||||
|
||||
@@ -14,6 +14,20 @@ typedef NS_ENUM(NSInteger, TokenType) {
|
||||
TokenTypeBasic = 1,
|
||||
TokenTypeBearer = 2
|
||||
};
|
||||
|
||||
/**
|
||||
* gets singleton object of current user session.
|
||||
*
|
||||
* @return singleton
|
||||
*/
|
||||
+ (instancetype _Nonnull) currentUser;
|
||||
|
||||
|
||||
///--------------------------------------
|
||||
#pragma mark - PNAccessToken Properties
|
||||
///--------------------------------------
|
||||
|
||||
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@@ -22,9 +36,18 @@ typedef NS_ENUM(NSInteger, TokenType) {
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic, strong, nullable) NSDate *expirationDate;
|
||||
|
||||
@property (nonatomic, strong, nullable) NSNumber *expiresIn;
|
||||
/**
|
||||
* <#Description#>
|
||||
*/
|
||||
@property (nonatomic) TokenType tokenType;
|
||||
|
||||
@property (nonatomic, strong, nullable) NSString *tokenTypeString;
|
||||
|
||||
@property (nonatomic, strong, nullable) NSString *scope;
|
||||
|
||||
@property (nonatomic, strong, nullable) NSString *refreshToken;
|
||||
|
||||
|
||||
@end
|
||||
@@ -7,6 +7,7 @@
|
||||
//
|
||||
|
||||
#import "PNAccessToken.h"
|
||||
#import <NSDate_Utils/NSDate+NSDate_Util.h>
|
||||
|
||||
@interface PNAccessToken() <PNObjectSubclassing>
|
||||
|
||||
@@ -19,13 +20,35 @@
|
||||
+ (NSDictionary *)objcetMapping {
|
||||
|
||||
NSDictionary *mapping = @{
|
||||
@"accessToken":@"accessToken",
|
||||
@"expirationDate":@"expirationDate",
|
||||
@"tokenType":@"tokenType",
|
||||
@"accessToken":@"access_token",
|
||||
@"expiresIn":@"expires_in",
|
||||
@"tokenTypeString":@"token_type",
|
||||
@"tokenType":@"scope",
|
||||
@"refreshToken":@"refresh_token",
|
||||
};
|
||||
return mapping;
|
||||
}
|
||||
|
||||
- (instancetype) initWithJSON:(NSDictionary *)JSON {
|
||||
self = [super initWithJSON:JSON];
|
||||
|
||||
if (self) {
|
||||
((void (^)())@{
|
||||
@"beaer" : ^{
|
||||
_tokenType = TokenTypeBearer;
|
||||
},
|
||||
@"basic" : ^{
|
||||
_tokenType = TokenTypeBasic;
|
||||
}
|
||||
}[_tokenTypeString] ?: ^{
|
||||
|
||||
})();
|
||||
|
||||
_expirationDate = [[NSDate date] dateByAddingHours:[_expiresIn integerValue]];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
+ (NSString *)objectClassName {
|
||||
return @"AccessToken";
|
||||
}
|
||||
@@ -38,7 +61,4 @@
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@end
|
||||
@@ -7,7 +7,7 @@
|
||||
//
|
||||
|
||||
#import "PNObject.h"
|
||||
|
||||
#import "PNAccessToken.h"
|
||||
|
||||
@interface PNUser : PNObject
|
||||
|
||||
@@ -33,7 +33,7 @@
|
||||
//- (void) setPassword:(NSString * _Nonnull)password inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id responseObject, NSError * error)) responseBlock;
|
||||
|
||||
///--------------------------------------
|
||||
#pragma mark - PNLocation Properties
|
||||
#pragma mark - PNUser Properties
|
||||
///--------------------------------------
|
||||
|
||||
/**
|
||||
|
||||
@@ -27,6 +27,9 @@
|
||||
NSDictionary *properties = [PNObject propertiesForClass:self.class];
|
||||
|
||||
for (NSString *propertyName in properties) {
|
||||
if ([propertyName isEqualToString:@"description"] || [propertyName isEqualToString:@"debugDescription"]) {
|
||||
continue;
|
||||
}
|
||||
[self addObserver:self forKeyPath:propertyName options:NSKeyValueObservingOptionNew context:nil];
|
||||
}
|
||||
|
||||
@@ -39,8 +42,11 @@
|
||||
NSString *mappedJSONType;
|
||||
|
||||
NSString *propertyType = [properties valueForKey:propertyName];
|
||||
NSLogDebug(@"%@",self.objectMapping);
|
||||
|
||||
id mappingValue = [self.objectMapping valueForKey:propertyName];
|
||||
NSLogDebug(@"%@",[[self class] objcetMapping]);
|
||||
|
||||
id mappingValue = [[[self class] objcetMapping] valueForKey:propertyName];
|
||||
|
||||
if([mappingValue isKindOfClass:NSDictionary.class]) {
|
||||
mappedJSONKey = [mappingValue valueForKey:@"key"];
|
||||
@@ -55,7 +61,7 @@
|
||||
}
|
||||
|
||||
// Get JSON value for the mapped key
|
||||
id value = [JSON valueForKeyPath:propertyName];
|
||||
id value = [JSON valueForKeyPath:mappedJSONKey];
|
||||
|
||||
|
||||
((void (^)())@{
|
||||
|
||||
+19
-10
@@ -259,6 +259,7 @@
|
||||
return _JSON;
|
||||
}
|
||||
|
||||
|
||||
- (NSDictionary* _Nonnull) getJSONObject {
|
||||
if (!_JSON) {
|
||||
return [self reverseMapping];
|
||||
@@ -307,7 +308,9 @@
|
||||
|
||||
- (id _Nonnull) saveLocally {
|
||||
|
||||
return [_objectModel saveLocally:self];
|
||||
__weak id weakSelf = self;
|
||||
|
||||
return [_objectModel saveLocally:weakSelf];
|
||||
}
|
||||
|
||||
- (BOOL) autoRemoveLocally {
|
||||
@@ -318,20 +321,26 @@
|
||||
|
||||
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
|
||||
{
|
||||
[_JSON setObject:[change objectForKey:@"new"] forKey:keyPath];
|
||||
NSLogDebug(@"%@",[[[self class] objcetMapping] objectForKey:keyPath]);
|
||||
[_JSON setObject:[change objectForKey:@"new"] forKey:[[[self class] objcetMapping] objectForKey:keyPath]];
|
||||
}
|
||||
|
||||
/*- (void)dealloc
|
||||
{
|
||||
- (void)dealloc
|
||||
{
|
||||
NSDictionary *properties = [PNObject propertiesForClass:self.class];
|
||||
|
||||
for (NSString *propertyName in properties) {
|
||||
if ([[PNObject protectedProperties] containsObject:propertyName]) {
|
||||
continue;
|
||||
}
|
||||
[self removeObserver:self forKeyPath:propertyName];
|
||||
if ([propertyName isEqualToString:@"description"] || [propertyName isEqualToString:@"debugDescription"]) {
|
||||
continue;
|
||||
}
|
||||
[self removeObserver:self forKeyPath:propertyName];
|
||||
}
|
||||
}
|
||||
*/
|
||||
_JSON = nil;
|
||||
_objectMapping = nil;
|
||||
_objID = nil;
|
||||
_createdAt = nil;
|
||||
|
||||
}
|
||||
|
||||
|
||||
@end
|
||||
@@ -39,134 +39,136 @@ static bool isFirstAccess = YES;
|
||||
|
||||
+ (instancetype)sharedInstance
|
||||
{
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
isFirstAccess = NO;
|
||||
SINGLETON = [[super allocWithZone:NULL] init];
|
||||
});
|
||||
|
||||
return SINGLETON;
|
||||
static dispatch_once_t onceToken;
|
||||
dispatch_once(&onceToken, ^{
|
||||
isFirstAccess = NO;
|
||||
SINGLETON = [[super allocWithZone:NULL] init];
|
||||
});
|
||||
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
#pragma mark - Life Cycle
|
||||
|
||||
+ (instancetype) initSharedInstanceForEnvironments:(NSDictionary *) endpointUrlsForEnvironments {
|
||||
SINGLETON = [self sharedInstance];
|
||||
|
||||
if (SINGLETON) {
|
||||
for (NSString *key in [endpointUrlsForEnvironments allKeys]) {
|
||||
|
||||
((void (^)())@{
|
||||
EnvironmentDevelopment : ^{
|
||||
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
|
||||
if (endpointUrl) {
|
||||
[SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key];
|
||||
SINGLETON.devEnabled = YES;
|
||||
}
|
||||
|
||||
},
|
||||
EnvironmentStage : ^{
|
||||
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
|
||||
if (endpointUrl) {
|
||||
[SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key];
|
||||
SINGLETON.stageEnabled = YES;
|
||||
}
|
||||
},
|
||||
EnvironmentProduction : ^{
|
||||
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
|
||||
if (endpointUrl) {
|
||||
[SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key];
|
||||
SINGLETON.productionEnabled = YES;
|
||||
}
|
||||
}
|
||||
}[key] ?: ^{
|
||||
|
||||
})();
|
||||
}
|
||||
NSAssert(SINGLETON.productionEnabled, @"EnvironmentProduction must be valid endpoint url");
|
||||
SINGLETON.currentEnvironment = [[SINGLETON configuration] objectForKey:EnvironmentProduction];
|
||||
|
||||
}
|
||||
return SINGLETON;
|
||||
SINGLETON = [self sharedInstance];
|
||||
|
||||
if (SINGLETON) {
|
||||
for (NSString *key in [endpointUrlsForEnvironments allKeys]) {
|
||||
|
||||
((void (^)())@{
|
||||
EnvironmentDevelopment : ^{
|
||||
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
|
||||
if (endpointUrl) {
|
||||
[SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key];
|
||||
SINGLETON.devEnabled = YES;
|
||||
}
|
||||
|
||||
},
|
||||
EnvironmentStage : ^{
|
||||
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
|
||||
if (endpointUrl) {
|
||||
[SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key];
|
||||
SINGLETON.stageEnabled = YES;
|
||||
}
|
||||
},
|
||||
EnvironmentProduction : ^{
|
||||
NSURL * endpointUrl = [NSURL URLWithString:[endpointUrlsForEnvironments objectForKey:key]];
|
||||
if (endpointUrl) {
|
||||
[SINGLETON.configuration setValue:[endpointUrl absoluteString] forKey:key];
|
||||
SINGLETON.productionEnabled = YES;
|
||||
}
|
||||
}
|
||||
}[key] ?: ^{
|
||||
|
||||
})();
|
||||
}
|
||||
NSAssert(SINGLETON.productionEnabled, @"EnvironmentProduction must be valid endpoint url");
|
||||
SINGLETON.currentEnvironment = [[SINGLETON configuration] objectForKey:EnvironmentProduction];
|
||||
|
||||
}
|
||||
return SINGLETON;
|
||||
}
|
||||
|
||||
+ (id) allocWithZone:(NSZone *)zone
|
||||
{
|
||||
return [self sharedInstance];
|
||||
return [self sharedInstance];
|
||||
}
|
||||
|
||||
+ (id)copyWithZone:(struct _NSZone *)zone
|
||||
{
|
||||
return [self sharedInstance];
|
||||
return [self sharedInstance];
|
||||
}
|
||||
|
||||
+ (id)mutableCopyWithZone:(struct _NSZone *)zone
|
||||
{
|
||||
return [self sharedInstance];
|
||||
return [self sharedInstance];
|
||||
}
|
||||
|
||||
- (id)copy
|
||||
{
|
||||
return [[PNObjectConfig alloc] init];
|
||||
return [[PNObjectConfig alloc] init];
|
||||
}
|
||||
|
||||
- (id)mutableCopy
|
||||
{
|
||||
return [[PNObjectConfig alloc] init];
|
||||
return [[PNObjectConfig alloc] init];
|
||||
}
|
||||
|
||||
- (id) init
|
||||
{
|
||||
if(SINGLETON){
|
||||
return SINGLETON;
|
||||
}
|
||||
if (isFirstAccess) {
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
}
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
_configuration = [[NSMutableDictionary alloc] init];
|
||||
_minPasswordLenght = minPassLenght;
|
||||
}
|
||||
return self;
|
||||
if(SINGLETON){
|
||||
return SINGLETON;
|
||||
}
|
||||
if (isFirstAccess) {
|
||||
[self doesNotRecognizeSelector:_cmd];
|
||||
}
|
||||
self = [super init];
|
||||
|
||||
if (self) {
|
||||
_configuration = [[NSMutableDictionary alloc] init];
|
||||
_minPasswordLenght = minPassLenght;
|
||||
|
||||
_manager = [AFHTTPSessionManager manager];
|
||||
}
|
||||
return self;
|
||||
}
|
||||
|
||||
- (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");
|
||||
|
||||
|
||||
_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;
|
||||
return _currentEnvironment;
|
||||
}
|
||||
|
||||
- (void) setAcceptablePasswordLenght:(NSUInteger) passLenght {
|
||||
_minPasswordLenght = passLenght;
|
||||
_minPasswordLenght = passLenght;
|
||||
}
|
||||
|
||||
@end
|
||||
Reference in new issue
Block a user