Commit a5f35086 by Brent Gulanowski

Change BUYClient.customerToken from string to BUYCustomerToken.

parent e81100f8
...@@ -119,7 +119,7 @@ ...@@ -119,7 +119,7 @@
return [self putRequestForURL:url object:nil completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) { return [self putRequestForURL:url object:nil completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
NSString *accessToken = nil; NSString *accessToken = nil;
if (json && !error) { if (json && !error) {
BUYCustomerToken *authenticatedResponse = [BUYCustomerToken responseWithJSON:json]; BUYCustomerToken *authenticatedResponse = [BUYCustomerToken customerTokenWithJSON:json];
accessToken = authenticatedResponse.accessToken; accessToken = authenticatedResponse.accessToken;
} }
...@@ -191,16 +191,16 @@ ...@@ -191,16 +191,16 @@
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) {
BUYCustomerToken *authenticatedResponse = [BUYCustomerToken customerTokenWithJSON:json]; BUYCustomerToken *authenticatedResponse = [BUYCustomerToken customerTokenWithJSON:json];
self.customerToken = authenticatedResponse.accessToken; self.customerToken = authenticatedResponse;
if (!customerJSON) { if (!customerJSON) {
[self getCustomerWithID:authenticatedResponse.customerID callback:^(BUYCustomer *customer, NSError *error) { [self getCustomerWithID:authenticatedResponse.customerID callback:^(BUYCustomer *customer, NSError *error) {
block(customer, self.customerToken, error); block(customer, self.customerToken.accessToken, error);
}]; }];
} }
else { else {
BUYCustomer *customer = [self.modelManager customerWithJSONDictionary:customerJSON]; BUYCustomer *customer = [self.modelManager customerWithJSONDictionary:customerJSON];
block(customer, self.customerToken, error); block(customer, self.customerToken.accessToken, error);
} }
} }
else { else {
......
...@@ -25,8 +25,9 @@ ...@@ -25,8 +25,9 @@
// //
@import Foundation; @import Foundation;
#import "BUYClientTypes.h" #import <Buy/BUYClientTypes.h>
@class BUYCustomerToken;
@class BUYModelManager; @class BUYModelManager;
@class BUYOperation; @class BUYOperation;
@class BUYRequestOperation; @class BUYRequestOperation;
...@@ -97,7 +98,7 @@ NS_ASSUME_NONNULL_BEGIN ...@@ -97,7 +98,7 @@ NS_ASSUME_NONNULL_BEGIN
* *
* @param token The token received from the create and login callbacks * @param token The token received from the create and login callbacks
*/ */
@property (strong, nonatomic, nullable) NSString *customerToken; @property (strong, nonatomic, nullable) BUYCustomerToken *customerToken;
@end @end
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#import "BUYClient+Internal.h" #import "BUYClient+Internal.h"
#import "BUYAssert.h" #import "BUYAssert.h"
#import "BUYCustomerToken.h"
#import "BUYModelManager.h" #import "BUYModelManager.h"
#import "BUYRequestOperation.h" #import "BUYRequestOperation.h"
...@@ -222,7 +223,7 @@ static NSString * const BUYClientJSONMimeType = @"application/json"; ...@@ -222,7 +223,7 @@ static NSString * const BUYClientJSONMimeType = @"application/json";
[request addValue:BUYClientJSONMimeType forHTTPHeaderField:@"Accept"]; [request addValue:BUYClientJSONMimeType forHTTPHeaderField:@"Accept"];
if (self.customerToken) { if (self.customerToken) {
[request addValue:self.customerToken forHTTPHeaderField:BUYClientCustomerAccessToken]; [request addValue:self.customerToken.accessToken forHTTPHeaderField:BUYClientCustomerAccessToken];
} }
request.HTTPMethod = method; request.HTTPMethod = method;
......
...@@ -27,6 +27,7 @@ ...@@ -27,6 +27,7 @@
#import "BUYWebCheckoutPaymentProvider.h" #import "BUYWebCheckoutPaymentProvider.h"
#import "BUYCheckout.h" #import "BUYCheckout.h"
#import "BUYClient+Checkout.h" #import "BUYClient+Checkout.h"
#import "BUYCustomerToken.h"
#import "BUYAssert.h" #import "BUYAssert.h"
@import SafariServices; @import SafariServices;
...@@ -176,11 +177,11 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token" ...@@ -176,11 +177,11 @@ static NSString *const WebCheckoutCustomerAccessToken = @"customer_access_token"
- (NSURL *)authenticatedWebCheckoutURL:(NSURL *)url - (NSURL *)authenticatedWebCheckoutURL:(NSURL *)url
{ {
NSString *customerToken = self.client.customerToken; NSString *accessToken = self.client.customerToken.accessToken;
if (!customerToken.length) { if (!accessToken.length) {
return url; return url;
} }
NSURLQueryItem *item = [NSURLQueryItem queryItemWithName:WebCheckoutCustomerAccessToken value:customerToken]; NSURLQueryItem *item = [NSURLQueryItem queryItemWithName:WebCheckoutCustomerAccessToken value:accessToken];
NSURLComponents *authenticatedComponents = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:YES]; NSURLComponents *authenticatedComponents = [NSURLComponents componentsWithURL:url resolvingAgainstBaseURL:YES];
authenticatedComponents.queryItems = authenticatedComponents.queryItems ? [authenticatedComponents.queryItems arrayByAddingObject:item] : @[item]; authenticatedComponents.queryItems = authenticatedComponents.queryItems ? [authenticatedComponents.queryItems arrayByAddingObject:item] : @[item];
return authenticatedComponents.URL; return authenticatedComponents.URL;
......
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