Commit 1cc02e5b by Brent Gulanowski

Rename method for clarity.

parent 8c219ebd
...@@ -191,7 +191,7 @@ ...@@ -191,7 +191,7 @@
NSURL *url = [self urlForCustomersToken]; NSURL *url = [self urlForCustomersToken];
return [self postRequestForURL:url object:credentials.JSONRepresentation completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) { return [self postRequestForURL:url object:credentials.JSONRepresentation completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
if (json && !error) { if (json && !error) {
self.customerToken = [BUYCustomerToken customerTokenWithJSON:json]; self.customerToken = [BUYCustomerToken customerTokenWithJSONDictionary:json];
if (!customerJSON) { if (!customerJSON) {
[self getCustomerCallback:^(BUYCustomer *customer, NSError *error) { [self getCustomerCallback:^(BUYCustomer *customer, NSError *error) {
block(customer, self.customerToken, error); block(customer, self.customerToken, error);
......
...@@ -35,6 +35,6 @@ ...@@ -35,6 +35,6 @@
- (instancetype)init NS_UNAVAILABLE; - (instancetype)init NS_UNAVAILABLE;
- (instancetype)initWithCustomerID:(NSNumber *)customerID accessToken:(NSString *)accessToken expiry:(NSDate *)expiry; - (instancetype)initWithCustomerID:(NSNumber *)customerID accessToken:(NSString *)accessToken expiry:(NSDate *)expiry;
+ (BUYCustomerToken *)customerTokenWithJSON:(NSDictionary *)json; + (BUYCustomerToken *)customerTokenWithJSONDictionary:(NSDictionary *)json;
@end @end
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#import "BUYCustomerToken.h" #import "BUYCustomerToken.h"
#import "NSDateFormatter+BUYAdditions.h" #import "NSDateFormatter+BUYAdditions.h"
#import "NSDictionary+BUYAdditions.h"
static NSString * const customerAccessTokenKey = @"customer_access_token"; static NSString * const customerAccessTokenKey = @"customer_access_token";
static NSString * const accessTokenKey = @"access_token"; static NSString * const accessTokenKey = @"access_token";
...@@ -36,6 +37,10 @@ static NSString * const customerIDKey = @"customer_id"; ...@@ -36,6 +37,10 @@ static NSString * const customerIDKey = @"customer_id";
- (instancetype)initWithCustomerID:(NSNumber *)customerID accessToken:(NSString *)accessToken expiry:(NSDate *)expiry - (instancetype)initWithCustomerID:(NSNumber *)customerID accessToken:(NSString *)accessToken expiry:(NSDate *)expiry
{ {
NSParameterAssert(customerID);
NSParameterAssert(accessToken);
NSParameterAssert(expiry);
self = [super init]; self = [super init];
if (self) { if (self) {
_customerID = customerID; _customerID = customerID;
...@@ -45,7 +50,7 @@ static NSString * const customerIDKey = @"customer_id"; ...@@ -45,7 +50,7 @@ static NSString * const customerIDKey = @"customer_id";
return self; return self;
} }
+ (BUYCustomerToken *)customerTokenWithJSON:(NSDictionary *)json + (BUYCustomerToken *)customerTokenWithJSONDictionary:(NSDictionary *)json
{ {
return [[self alloc] initWithJSON:json]; return [[self alloc] initWithJSON:json];
} }
...@@ -53,7 +58,7 @@ static NSString * const customerIDKey = @"customer_id"; ...@@ -53,7 +58,7 @@ static NSString * const customerIDKey = @"customer_id";
- (instancetype)initWithJSON:(NSDictionary *)json - (instancetype)initWithJSON:(NSDictionary *)json
{ {
NSDateFormatter *formatter = [NSDateFormatter dateFormatterForPublications]; NSDateFormatter *formatter = [NSDateFormatter dateFormatterForPublications];
NSDictionary *access = json[customerAccessTokenKey]; NSDictionary *access = json[customerAccessTokenKey] ?: json;
NSNumber *customerID = access[customerIDKey]; NSNumber *customerID = access[customerIDKey];
NSString *accessToken = access[accessTokenKey]; NSString *accessToken = access[accessTokenKey];
......
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