- Refactoring classes

- Add Installation Class
- Add AccessToken Class (not yet complete)
- Remove PNObjectProperty
- Move PNObjectProperty methods to "PNObject+Protected.h"
This commit is contained in:
giuseppenuc committed 2016-01-27 15:14:04 +01:00
1 parent 1efd26a133
commit fad171373e
24 files changed
+1358 -945

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
//
// PNAccessToken.h
// Pods
//
// Created by Giuseppe Nucifora on 27/01/16.
//
//
#import <PNObject/PNObject.h>
@interface PNAccessToken : PNObject
typedef NS_ENUM(NSInteger, TokenType) {
TokenTypeBasic = 1,
TokenTypeBearer = 2
};
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSString *accessToken;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSDate *expirationDate;
/**
* <#Description#>
*/
@property (nonatomic) TokenType tokenType;
@end
+44
View File
@@ -0,0 +1,44 @@
//
// PNAccessToken.m
// Pods
//
// Created by Giuseppe Nucifora on 27/01/16.
//
//
#import "PNAccessToken.h"
@interface PNAccessToken() <PNObjectSubclassing>
@end
@implementation PNAccessToken
#pragma mark PNObjectSubclassing Protocol
+ (NSDictionary *)objcetMapping {
NSDictionary *mapping = @{
@"accessToken":@"accessToken",
@"expirationDate":@"expirationDate",
@"tokenType":@"tokenType",
};
return mapping;
}
+ (NSString *)objectClassName {
return @"AccessToken";
}
+ (BOOL) singleInstance {
return YES;
}
#pragma mark -
@end
+51
View File
@@ -0,0 +1,51 @@
//
// PNAddress.h
// Pods
//
// Created by Giuseppe Nucifora on 13/01/16.
//
//
#import "PNObject.h"
#import "PNLocation.h"
@interface PNAddress : PNObject <PNObjectSubclassing>
///--------------------------------------
#pragma mark - PNAddress Properties
///--------------------------------------
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSString * country;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSString * province;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSString * city;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSString * street;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSNumber * number;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSString * zip;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSString * istruction;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) PNLocation * location;
@end
+33
View File
@@ -0,0 +1,33 @@
//
// PNAddress.m
// Pods
//
// Created by Giuseppe Nucifora on 13/01/16.
//
//
#import "PNAddress.h"
@implementation PNAddress
+ (NSString *) objectClassName {
return @"Address";
}
+ (NSDictionary *) objcetMapping {
NSDictionary *mapping = @{@"country":@"country",
@"province":@"province",
@"city":@"city",
@"street":@"street",
@"number":@"number",
@"zip":@"zip",
@"location":@{@"key":@"location",@"type":@"PNLocation"},
};
return mapping;
}
+ (BOOL)singleInstance {
return NO;
}
@end
+59
View File
@@ -0,0 +1,59 @@
//
// PNInstallation.h
// Pods
//
// Created by Giuseppe Nucifora on 27/01/16.
//
//
#import <PNObject/PNObject.h>
@interface PNInstallation : PNObject
/**
Gets the currently-running installation from disk and returns an instance of it.
If this installation is not stored on disk, returns a `PFInstallation`
with `deviceType` and `installationId` fields set to those of the
current installation.
@result Returns a `Installation` that represents the currently-running installation.
*/
+ (instancetype _Nonnull)currentInstallation;
- (void)setDeviceTokenFromData:(nullable NSData *)deviceTokenData;
///--------------------------------------
#pragma mark - PNInstallation Properties
///--------------------------------------
/**
* <#Description#>
*/
@property (nonatomic, strong, readonly, nonnull) NSString *deviceType;
/**
* <#Description#>
*/
@property (nonatomic, strong, readonly, nonnull) NSString *deviceModel;
/**
* <#Description#>
*/
@property (nonatomic, strong, readonly, nonnull) NSString *deviceName;
/**
* <#Description#>
*/
@property (nonatomic, strong, readonly, nonnull) NSString *osVersion;
/**
* <#Description#>
*/
@property (nonatomic, strong, readonly, nonnull) NSString *localeIdentifier;
/**
* <#Description#>
*/
@property (nonatomic, strong, readonly, nullable) NSString *deviceToken;
/**
* <#Description#>
*/
@property (nonatomic, assign) NSInteger badge;
@end
+111
View File
@@ -0,0 +1,111 @@
//
// PNInstallation.m
// Pods
//
// Created by Giuseppe Nucifora on 27/01/16.
//
//
#import "PNInstallation.h"
@interface PNInstallation() <PNObjectSubclassing>
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSData *deviceTokenData;
@end
@implementation PNInstallation
static PNInstallation *SINGLETON = nil;
static bool isFirstAccess = YES;
#pragma mark PNObjectSubclassing Protocol
+ (NSDictionary *)objcetMapping {
NSDictionary *mapping = @{
@"deviceType":@"deviceType",
@"deviceModel":@"deviceModel",
@"deviceName":@"deviceName",
@"osVersion":@"osVersion",
@"deviceToken":@"deviceToken",
@"badge":@"badge",
@"localeIdentifier":@"localeIdentifier",
};
return mapping;
}
+ (NSString *)objectClassName {
return @"AccessToken";
}
+ (BOOL) singleInstance {
return YES;
}
#pragma mark -
#pragma mark Public Methods
+ (instancetype) currentInstallation {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] init];
});
return SINGLETON;
}
- (void)setDeviceTokenFromData:(NSData *)deviceTokenData {
_deviceTokenData = deviceTokenData;
NSString *ptoken = [[[[deviceTokenData description]
stringByReplacingOccurrencesOfString:@"<"withString:@""]
stringByReplacingOccurrencesOfString:@">" withString:@""]
stringByReplacingOccurrencesOfString: @" " withString: @""];
_deviceToken = ptoken;
}
#pragma mark -
#pragma mark Private Methods
- (id) init
{
if(SINGLETON){
return SINGLETON;
}
if (isFirstAccess) {
[self doesNotRecognizeSelector:_cmd];
}
NSDictionary *savedInstallation = [[PNObjectModel sharedInstance] fetchObjectsWithClass:[self class]];
if (savedInstallation) {
self = [super initWithJSON:savedInstallation];
}
else {
self = [super init];
}
if (self) {
_deviceModel = [[UIDevice currentDevice] model];
_osVersion = [[UIDevice currentDevice] systemVersion];;
_deviceName = [[UIDevice currentDevice] name];;
}
return self;
}
#pragma mark -
@end
+26
View File
@@ -0,0 +1,26 @@
//
// PNLocation.h
// Pods
//
// Created by Giuseppe Nucifora on 13/01/16.
//
//
#import "PNObject.h"
@interface PNLocation : PNObject <PNObjectSubclassing>
///--------------------------------------
#pragma mark - PNLocation Properties
///--------------------------------------
/**
* <#Description#>
*/
@property (nonatomic) CGFloat lat;
/**
* <#Description#>
*/
@property (nonatomic) CGFloat lng;
@end
+29
View File
@@ -0,0 +1,29 @@
//
// PNLocation.m
// Pods
//
// Created by Giuseppe Nucifora on 13/01/16.
//
//
#import "PNLocation.h"
@implementation PNLocation
+ (NSString *) objectClassName {
return @"Location";
}
+ (NSDictionary *) objcetMapping {
NSDictionary *mapping = @{@"lat":@"lat",
@"lng":@"lng",
};
return mapping;
}
+ (BOOL)singleInstance {
return NO;
}
@end
+103
View File
@@ -0,0 +1,103 @@
//
// PNUser.h
// Pods
//
// Created by Giuseppe Nucifora on 15/01/16.
//
//
#import "PNObject.h"
@interface PNUser : PNObject
/**
* gets singleton object of current user session.
*
* @return singleton
*/
+ (instancetype _Nonnull) currentUser;
- (BOOL) isValidPassword:(NSString* _Nonnull) password;
//- (void) setPassword:(NSString * _Nonnull)password inBackGroundWithBlock:(nullable void (^)(BOOL saveStatus, id responseObject, NSError * error)) responseBlock;
///--------------------------------------
#pragma mark - PNLocation Properties
///--------------------------------------
/**
* <#Description#>
*/
@property (strong, nonatomic, nonnull) NSString * userId;
/**
* <#Description#>
*/
@property (strong, nonatomic, nonnull) NSString * firstName;
/**
* <#Description#>
*/
@property (strong, nonatomic, nonnull) NSString * lastName;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) UIImage * profileImage;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSString * sex;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSDate * birthDate;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSString * phone;
/**
* <#Description#>
*/
@property (nonatomic) BOOL hasAcceptedPrivacy;
/**
* <#Description#>
*/
@property (nonatomic) BOOL hasAcceptedNewsletter;
/**
* <#Description#>
*/
@property (nonatomic) BOOL hasVerifiedEmail;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSDate * emailVerifiedDate;
/**
* <#Description#>
*/
@property (nonatomic, strong, nonnull) NSString * email;
/**
* <#Description#>
*/
@property (nonatomic, strong, nonnull) NSString * username;
/**
* <#Description#>
*/
@property (nonatomic, strong, nonnull) NSString * password;
/**
* <#Description#>
*/
@property (nonatomic) BOOL publicProfile;
/**
* <#Description#>
*/
@property (nonatomic, strong, nonnull) NSNumber * loginCount;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSString * facebookId;
/**
* <#Description#>
*/
@property (nonatomic, strong, nullable) NSString * facebookAccessToken;
@end
+156
View File
@@ -0,0 +1,156 @@
//
// PNUser.m
// Pods
//
// Created by Giuseppe Nucifora on 15/01/16.
//
//
#import "PNUser.h"
#import "NSString+Helper.h"
#import "PNObjectConstants.h"
#import "PNObject+Protected.h"
@interface PNUser() <PNObjectSubclassing>
@end
@implementation PNUser
@synthesize password = _password;
static PNUser *SINGLETON = nil;
static bool isFirstAccess = YES;
#pragma mark - Public Method
+ (instancetype) currentUser {
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
isFirstAccess = NO;
SINGLETON = [[super allocWithZone:NULL] init];
});
return SINGLETON;
}
#pragma mark - Life Cycle
+ (instancetype) allocWithZone:(NSZone *)zone
{
return [self currentUser];
}
+ (instancetype)copyWithZone:(struct _NSZone *)zone
{
return [self currentUser];
}
+ (instancetype)mutableCopyWithZone:(struct _NSZone *)zone
{
return [self currentUser];
}
- (instancetype)copy
{
return [[PNUser alloc] init];
}
- (instancetype)mutableCopy
{
return [[PNUser alloc] init];
}
- (id) init
{
if(SINGLETON){
return SINGLETON;
}
if (isFirstAccess) {
[self doesNotRecognizeSelector:_cmd];
}
NSDictionary *savedUser = [[PNObjectModel sharedInstance] fetchObjectsWithClass:[self class]];
if (savedUser) {
self = [super initWithJSON:savedUser];
}
else {
self = [super init];
}
if (self) {
}
return self;
}
- (void) setEmail:(NSString *)email {
if ([email isValidEmail]) {
_email = email;
}
NSLogDebug(@"insertedEmail is not valid.");
}
- (void) setPassword:(NSString *)password {
if ([self isValidPassword:password]) {
_password = password;
}
else {
NSLogDebug(@"Inserted Passord is not valid.Lenght must be >= %ld",(long)[[PNObjectConfig sharedInstance] minPasswordLenght]);
}
}
- (BOOL) isValidPassword:(NSString* _Nonnull) password {
if ([password length] >= [[PNObjectConfig sharedInstance] minPasswordLenght]) {
return YES;
}
return NO;
}
- (NSString *) password {
return @"password is not readble";
}
#pragma mark PNObjectSubclassing Protocol
+ (NSDictionary *)objcetMapping {
NSDictionary *mapping = @{
@"userId":@"id",
@"firstName":@"firstName",
@"lastName":@"lastName",
@"profileImage":@"profileImage",
@"sex":@"sex",
@"birthDate":@"birthDate",
@"phone":@"phone",
@"password":@"password",
@"hasAcceptedPrivacy":@"hasAcceptedPrivacy",
@"hasAcceptedNewsletter":@"hasAcceptedNewsletter",
@"hasVerifiedEmail":@"hasVerifiedEmail",
@"emailVerifiedDate":@"emailVerifiedDate",
@"email":@"email",
@"username":@"username",
@"publicProfile":@"public_profile",
@"loginCount":@"login_count",
@"facebookId":@"facebookId",
@"facebookAccessToken":@"facebookAccessToken",
};
return mapping;
}
+ (NSString *)objectClassName {
return @"User";
}
+ (BOOL) singleInstance {
return YES;
}
#pragma mark -
@end