Commit f71fad65 by Dima Bart

Add empty initializer for credentials, count property. Minor refactoring.

parent 34374ba6
...@@ -41,9 +41,11 @@ extern NSString * const BUYAccountPasswordConfirmationKey; ...@@ -41,9 +41,11 @@ extern NSString * const BUYAccountPasswordConfirmationKey;
*/ */
@interface BUYAccountCredentials : NSObject @interface BUYAccountCredentials : NSObject
@property (nonatomic, assign, readonly) NSUInteger count;
@property (nonatomic, assign, readonly, getter=isValid) BOOL valid; @property (nonatomic, assign, readonly, getter=isValid) BOOL valid;
@property (nonatomic, strong, readonly) NSDictionary *JSONRepresentation; @property (nonatomic, strong, readonly) NSDictionary *JSONRepresentation;
+ (BUYAccountCredentials *)credentials;
+ (BUYAccountCredentials *)credentialsWithItems:(nullable NSArray<BUYAccountCredentialItem *> *)items; + (BUYAccountCredentials *)credentialsWithItems:(nullable NSArray<BUYAccountCredentialItem *> *)items;
- (instancetype)initWithItems:(nullable NSArray<BUYAccountCredentialItem *> *)items; - (instancetype)initWithItems:(nullable NSArray<BUYAccountCredentialItem *> *)items;
......
...@@ -41,6 +41,11 @@ NSString * const BUYAccountPasswordConfirmationKey = @"password_confirmation"; ...@@ -41,6 +41,11 @@ NSString * const BUYAccountPasswordConfirmationKey = @"password_confirmation";
@implementation BUYAccountCredentials @implementation BUYAccountCredentials
+ (BUYAccountCredentials *)credentials
{
return [BUYAccountCredentials credentialsWithItems:nil];
}
+ (BUYAccountCredentials *)credentialsWithItems:(NSArray<BUYAccountCredentialItem *> *)items + (BUYAccountCredentials *)credentialsWithItems:(NSArray<BUYAccountCredentialItem *> *)items
{ {
return [[BUYAccountCredentials alloc] initWithItems:items]; return [[BUYAccountCredentials alloc] initWithItems:items];
...@@ -60,6 +65,11 @@ NSString * const BUYAccountPasswordConfirmationKey = @"password_confirmation"; ...@@ -60,6 +65,11 @@ NSString * const BUYAccountPasswordConfirmationKey = @"password_confirmation";
} }
#pragma mark - Accessors - #pragma mark - Accessors -
- (NSUInteger)count
{
return self.items.count;
}
- (BOOL)isValid - (BOOL)isValid
{ {
__block BOOL valid = YES; __block BOOL valid = YES;
...@@ -104,27 +114,27 @@ NSString * const BUYAccountPasswordConfirmationKey = @"password_confirmation"; ...@@ -104,27 +114,27 @@ NSString * const BUYAccountPasswordConfirmationKey = @"password_confirmation";
#pragma mark - Init - #pragma mark - Init -
+ (instancetype)itemEmailWithValue:(NSString *)value + (instancetype)itemEmailWithValue:(NSString *)value
{ {
return [[BUYAccountCredentialItem alloc] initWithKey:BUYAccountEmailKey value:value]; return [BUYAccountCredentialItem itemWithKey:BUYAccountEmailKey value:value];
} }
+ (instancetype)itemFirstNameWithValue:(NSString *)value + (instancetype)itemFirstNameWithValue:(NSString *)value
{ {
return [[BUYAccountCredentialItem alloc] initWithKey:BUYAccountFirstNameKey value:value]; return [BUYAccountCredentialItem itemWithKey:BUYAccountFirstNameKey value:value];
} }
+ (instancetype)itemLastNameWithValue:(NSString *)value + (instancetype)itemLastNameWithValue:(NSString *)value
{ {
return [[BUYAccountCredentialItem alloc] initWithKey:BUYAccountLastNameKey value:value]; return [BUYAccountCredentialItem itemWithKey:BUYAccountLastNameKey value:value];
} }
+ (instancetype)itemPasswordWithValue:(NSString *)value + (instancetype)itemPasswordWithValue:(NSString *)value
{ {
return [[BUYAccountCredentialItem alloc] initWithKey:BUYAccountPasswordKey value:value]; return [BUYAccountCredentialItem itemWithKey:BUYAccountPasswordKey value:value];
} }
+ (instancetype)itemPasswordConfirmationWithValue:(NSString *)value + (instancetype)itemPasswordConfirmationWithValue:(NSString *)value
{ {
return [[BUYAccountCredentialItem alloc] initWithKey:BUYAccountPasswordConfirmationKey value:value]; return [BUYAccountCredentialItem itemWithKey:BUYAccountPasswordConfirmationKey value:value];
} }
+ (instancetype)itemWithKey:(NSString *)key value:(NSString *)value + (instancetype)itemWithKey:(NSString *)key value:(NSString *)value
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment