Commit f71fad65 by Dima Bart

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

parent 34374ba6
......@@ -41,9 +41,11 @@ extern NSString * const BUYAccountPasswordConfirmationKey;
*/
@interface BUYAccountCredentials : NSObject
@property (nonatomic, assign, readonly) NSUInteger count;
@property (nonatomic, assign, readonly, getter=isValid) BOOL valid;
@property (nonatomic, strong, readonly) NSDictionary *JSONRepresentation;
+ (BUYAccountCredentials *)credentials;
+ (BUYAccountCredentials *)credentialsWithItems:(nullable NSArray<BUYAccountCredentialItem *> *)items;
- (instancetype)initWithItems:(nullable NSArray<BUYAccountCredentialItem *> *)items;
......
......@@ -41,6 +41,11 @@ NSString * const BUYAccountPasswordConfirmationKey = @"password_confirmation";
@implementation BUYAccountCredentials
+ (BUYAccountCredentials *)credentials
{
return [BUYAccountCredentials credentialsWithItems:nil];
}
+ (BUYAccountCredentials *)credentialsWithItems:(NSArray<BUYAccountCredentialItem *> *)items
{
return [[BUYAccountCredentials alloc] initWithItems:items];
......@@ -60,6 +65,11 @@ NSString * const BUYAccountPasswordConfirmationKey = @"password_confirmation";
}
#pragma mark - Accessors -
- (NSUInteger)count
{
return self.items.count;
}
- (BOOL)isValid
{
__block BOOL valid = YES;
......@@ -104,27 +114,27 @@ NSString * const BUYAccountPasswordConfirmationKey = @"password_confirmation";
#pragma mark - Init -
+ (instancetype)itemEmailWithValue:(NSString *)value
{
return [[BUYAccountCredentialItem alloc] initWithKey:BUYAccountEmailKey value:value];
return [BUYAccountCredentialItem itemWithKey:BUYAccountEmailKey value:value];
}
+ (instancetype)itemFirstNameWithValue:(NSString *)value
{
return [[BUYAccountCredentialItem alloc] initWithKey:BUYAccountFirstNameKey value:value];
return [BUYAccountCredentialItem itemWithKey:BUYAccountFirstNameKey value:value];
}
+ (instancetype)itemLastNameWithValue:(NSString *)value
{
return [[BUYAccountCredentialItem alloc] initWithKey:BUYAccountLastNameKey value:value];
return [BUYAccountCredentialItem itemWithKey:BUYAccountLastNameKey value:value];
}
+ (instancetype)itemPasswordWithValue:(NSString *)value
{
return [[BUYAccountCredentialItem alloc] initWithKey:BUYAccountPasswordKey value:value];
return [BUYAccountCredentialItem itemWithKey:BUYAccountPasswordKey value: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
......
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