diff --git a/Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m b/Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m index af62248..90364e5 100644 --- a/Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m +++ b/Mobile Buy SDK/Mobile Buy SDK/Data/BUYClient+Customers.m @@ -191,7 +191,7 @@ NSURL *url = [self urlForCustomersToken]; return [self postRequestForURL:url object:credentials.JSONRepresentation completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) { if (json && !error) { - self.customerToken = [BUYCustomerToken customerTokenWithJSON:json]; + self.customerToken = [BUYCustomerToken customerTokenWithJSONDictionary:json]; if (!customerJSON) { [self getCustomerCallback:^(BUYCustomer *customer, NSError *error) { block(customer, self.customerToken, error); diff --git a/Mobile Buy SDK/Mobile Buy SDK/Models/BUYCustomerToken.h b/Mobile Buy SDK/Mobile Buy SDK/Models/BUYCustomerToken.h index bf0f97b..032c47e 100644 --- a/Mobile Buy SDK/Mobile Buy SDK/Models/BUYCustomerToken.h +++ b/Mobile Buy SDK/Mobile Buy SDK/Models/BUYCustomerToken.h @@ -35,6 +35,6 @@ - (instancetype)init NS_UNAVAILABLE; - (instancetype)initWithCustomerID:(NSNumber *)customerID accessToken:(NSString *)accessToken expiry:(NSDate *)expiry; -+ (BUYCustomerToken *)customerTokenWithJSON:(NSDictionary *)json; ++ (BUYCustomerToken *)customerTokenWithJSONDictionary:(NSDictionary *)json; @end diff --git a/Mobile Buy SDK/Mobile Buy SDK/Models/BUYCustomerToken.m b/Mobile Buy SDK/Mobile Buy SDK/Models/BUYCustomerToken.m index 4bc4f63..560b84c 100644 --- a/Mobile Buy SDK/Mobile Buy SDK/Models/BUYCustomerToken.m +++ b/Mobile Buy SDK/Mobile Buy SDK/Models/BUYCustomerToken.m @@ -26,6 +26,7 @@ #import "BUYCustomerToken.h" #import "NSDateFormatter+BUYAdditions.h" +#import "NSDictionary+BUYAdditions.h" static NSString * const customerAccessTokenKey = @"customer_access_token"; static NSString * const accessTokenKey = @"access_token"; @@ -36,6 +37,10 @@ static NSString * const customerIDKey = @"customer_id"; - (instancetype)initWithCustomerID:(NSNumber *)customerID accessToken:(NSString *)accessToken expiry:(NSDate *)expiry { + NSParameterAssert(customerID); + NSParameterAssert(accessToken); + NSParameterAssert(expiry); + self = [super init]; if (self) { _customerID = customerID; @@ -45,7 +50,7 @@ static NSString * const customerIDKey = @"customer_id"; return self; } -+ (BUYCustomerToken *)customerTokenWithJSON:(NSDictionary *)json ++ (BUYCustomerToken *)customerTokenWithJSONDictionary:(NSDictionary *)json { return [[self alloc] initWithJSON:json]; } @@ -53,7 +58,7 @@ static NSString * const customerIDKey = @"customer_id"; - (instancetype)initWithJSON:(NSDictionary *)json { NSDateFormatter *formatter = [NSDateFormatter dateFormatterForPublications]; - NSDictionary *access = json[customerAccessTokenKey]; + NSDictionary *access = json[customerAccessTokenKey] ?: json; NSNumber *customerID = access[customerIDKey]; NSString *accessToken = access[accessTokenKey];