Commit 15b25a23 by Dima Bart

Update deprecated orders API, add tests, update stubs.

parent 383d64fd
...@@ -114,10 +114,6 @@ ...@@ -114,10 +114,6 @@
@"https://_DOMAIN_/api/customers.json" @"https://_DOMAIN_/api/customers.json"
); );
XCTAssertEqualObjects( XCTAssertEqualObjects(
[self.client urlForCustomersOrders].absoluteString,
@"https://_DOMAIN_/api/customers/orders.json"
);
XCTAssertEqualObjects(
[self.client urlForCustomersToken].absoluteString, [self.client urlForCustomersToken].absoluteString,
@"https://_DOMAIN_/api/customers/customer_token.json" @"https://_DOMAIN_/api/customers/customer_token.json"
); );
...@@ -126,6 +122,14 @@ ...@@ -126,6 +122,14 @@
@"https://_DOMAIN_/api/customers/recover.json" @"https://_DOMAIN_/api/customers/recover.json"
); );
XCTAssertEqualObjects( XCTAssertEqualObjects(
[self.client urlForCustomersOrdersWithID:identifier].absoluteString,
@"https://_DOMAIN_/api/customers/_ID_/orders.json"
);
XCTAssertEqualObjects(
[self.client urlForCustomersOrdersWithID:identifier orderID:@99].absoluteString,
@"https://_DOMAIN_/api/customers/_ID_/orders/99.json"
);
XCTAssertEqualObjects(
[self.client urlForCustomersWithID:identifier].absoluteString, [self.client urlForCustomersWithID:identifier].absoluteString,
@"https://_DOMAIN_/api/customers/_ID_.json" @"https://_DOMAIN_/api/customers/_ID_.json"
); );
......
...@@ -357,12 +357,12 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg"; ...@@ -357,12 +357,12 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
- (void)testGetOrdersForCustomerURL - (void)testGetOrdersForCustomerURL
{ {
BUYRequestOperation *task = [self.client getOrdersForCustomerWithCallback:^(NSArray<BUYOrder *> *orders, NSError *error) { BUYRequestOperation *task = [self.client getOrdersForCustomerWithID:@"99" callback:^(NSArray<BUYOrder *> *orders, NSError *error) {
}]; }];
XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https"); XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/customers/orders.json"); XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/customers/99/orders.json");
XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET"); XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET");
XCTAssertEqualObjects(self.client.customerToken, task.originalRequest.allHTTPHeaderFields[BUYClientCustomerAccessToken]); XCTAssertEqualObjects(self.client.customerToken, task.originalRequest.allHTTPHeaderFields[BUYClientCustomerAccessToken]);
......
...@@ -49,6 +49,7 @@ extern NSString * const BUYFakeCustomerToken; ...@@ -49,6 +49,7 @@ extern NSString * const BUYFakeCustomerToken;
@property (nonatomic, strong) NSString *discountCodeValid; @property (nonatomic, strong) NSString *discountCodeValid;
@property (nonatomic, strong) NSString *discountCodeExpired; @property (nonatomic, strong) NSString *discountCodeExpired;
@property (nonatomic, strong) NSArray<NSNumber *> *customerOrderIDs;
@property (nonatomic, strong) NSArray *productIds; @property (nonatomic, strong) NSArray *productIds;
@property (nonatomic, strong) NSNumber *variantUntrackedId; @property (nonatomic, strong) NSNumber *variantUntrackedId;
@property (nonatomic, strong) NSNumber *variantInventory1Id; @property (nonatomic, strong) NSNumber *variantInventory1Id;
......
...@@ -26,6 +26,7 @@ ...@@ -26,6 +26,7 @@
#import "BUYClientTestBase.h" #import "BUYClientTestBase.h"
#import "BUYTestConstants.h" #import "BUYTestConstants.h"
#import "NSArray+BUYAdditions.h"
NSString * const BUYShopDomain_Placeholder = @"test_shop"; NSString * const BUYShopDomain_Placeholder = @"test_shop";
NSString * const BUYAPIKey_Placeholder = @"api_key"; NSString * const BUYAPIKey_Placeholder = @"api_key";
...@@ -55,6 +56,7 @@ NSString * const BUYAppId_Placeholder = @"app_id"; ...@@ -55,6 +56,7 @@ NSString * const BUYAppId_Placeholder = @"app_id";
self.customerEmail = environment[kBUYTestEmail] ?: jsonConfig[kBUYTestEmail]; self.customerEmail = environment[kBUYTestEmail] ?: jsonConfig[kBUYTestEmail];
self.customerPassword = environment[kBUYTestPassword] ?: jsonConfig[kBUYTestPassword]; self.customerPassword = environment[kBUYTestPassword] ?: jsonConfig[kBUYTestPassword];
self.customerOrderIDs = environment[kBUYTestOrderIds] ?: jsonConfig[kBUYTestOrderIds];
NSDictionary *giftCards = jsonConfig[@"gift_cards"]; NSDictionary *giftCards = jsonConfig[@"gift_cards"];
......
...@@ -57,11 +57,11 @@ ...@@ -57,11 +57,11 @@
- (void)loginDefaultCustomer - (void)loginDefaultCustomer
{ {
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest * _Nonnull request) { if (self.customer) {
return [self shouldUseMocks]; return;
} withStubResponse:^OHHTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) { }
return [OHHTTPStubsResponse responseWithKey:@"testCustomerLogin"];
}]; [OHHTTPStubs stubUsingResponseWithKey:@"testCustomerLogin" useMocks:[self shouldUseMocks]];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client loginCustomerWithCredentials:[self credentialsForLogin] callback:^(BUYCustomer *customer, NSString *token, NSError *error) { [self.client loginCustomerWithCredentials:[self credentialsForLogin] callback:^(BUYCustomer *customer, NSString *token, NSError *error) {
...@@ -150,23 +150,57 @@ ...@@ -150,23 +150,57 @@
- (void)testCustomerLogout - (void)testCustomerLogout
{ {
[OHHTTPStubs stubUsingResponseWithKey:@"testCustomerLogin" useMocks:[self shouldUseMocks]]; [OHHTTPStubs stubUsingResponseWithKey:@"testCustomerLogout" useMocks:[self shouldUseMocks]];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)]; XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client loginCustomerWithCredentials:[self credentialsForLogin] callback:^(BUYCustomer *customer, NSString *token, NSError *error) { [self.client logoutCustomerID:self.customer.identifier.stringValue callback:^(BUYStatus status, NSError * _Nullable error) {
[OHHTTPStubs stubUsingResponseWithKey:@"testCustomerLogout" useMocks:[self shouldUseMocks]]; XCTAssertNil(error);
XCTAssertEqual(status, 204);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:10 handler:nil];
}
[self.client logoutCustomerID:customer.identifier.stringValue callback:^(BUYStatus status, NSError * _Nullable error) { #pragma mark - Orders -
- (void)testCustomerOrders
{
[OHHTTPStubs stubUsingResponseWithKey:@"testCustomerGetOrders" useMocks:[self shouldUseMocks]];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client getOrdersForCustomerWithID:self.customer.identifier.stringValue callback:^(NSArray<BUYOrder *> * _Nullable orders, NSError * _Nullable error) {
XCTAssertNotNil(orders);
XCTAssertNil(error); XCTAssertNil(error);
XCTAssertEqual(status, 204);
XCTAssertTrue(orders.count > 0);
XCTAssertTrue([orders.firstObject isKindOfClass:[BUYOrder class]]);
[expectation fulfill]; [expectation fulfill];
}]; }];
[self waitForExpectationsWithTimeout:10.0 handler:nil];
}
- (void)testCustomerOrderWithID
{
[OHHTTPStubs stubUsingResponseWithKey:@"testCustomerGetOrder" useMocks:[self shouldUseMocks]];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client getOrderWithID:self.customerOrderIDs.firstObject customerID:self.customer.identifier.stringValue callback:^(BUYOrder * _Nullable order, NSError * _Nullable error) {
XCTAssertNotNil(order);
XCTAssertNil(error);
XCTAssertTrue([order isKindOfClass:[BUYOrder class]]);
[expectation fulfill];
}]; }];
[self waitForExpectationsWithTimeout:10 handler:nil]; [self waitForExpectationsWithTimeout:10.0 handler:nil];
} }
#pragma mark - Update - #pragma mark - Update -
......
...@@ -34,6 +34,7 @@ ...@@ -34,6 +34,7 @@
#define kBUYTestMerchantId @"merchant_id" #define kBUYTestMerchantId @"merchant_id"
#define kBUYTestEmail @"customer_email" #define kBUYTestEmail @"customer_email"
#define kBUYTestPassword @"customer_password" #define kBUYTestPassword @"customer_password"
#define kBUYTestOrderIds @"customer_order_ids"
#define kBUYTestGiftCardCode11 @"gift_card_code_11" #define kBUYTestGiftCardCode11 @"gift_card_code_11"
#define kBUYTestGiftCardCode25 @"gift_card_code_25" #define kBUYTestGiftCardCode25 @"gift_card_code_25"
#define kBUYTestGiftCardCode50 @"gift_card_code_50" #define kBUYTestGiftCardCode50 @"gift_card_code_50"
......
...@@ -34,7 +34,6 @@ ...@@ -34,7 +34,6 @@
@interface OHHTTPStubs (Buy) @interface OHHTTPStubs (Buy)
+ (void)stubUsingResponseWithKey:(NSString *)key;
+ (void)stubUsingResponseWithKey:(NSString *)key useMocks:(BOOL)useMocks; + (void)stubUsingResponseWithKey:(NSString *)key useMocks:(BOOL)useMocks;
@end @end
...@@ -55,11 +55,6 @@ ...@@ -55,11 +55,6 @@
@implementation OHHTTPStubs (Buy) @implementation OHHTTPStubs (Buy)
+ (void)stubUsingResponseWithKey:(NSString *)key
{
[self stubUsingResponseWithKey:key useMocks:YES];
}
+ (void)stubUsingResponseWithKey:(NSString *)key useMocks:(BOOL)useMocks + (void)stubUsingResponseWithKey:(NSString *)key useMocks:(BOOL)useMocks
{ {
if (useMocks) { if (useMocks) {
......
...@@ -128,5 +128,7 @@ ...@@ -128,5 +128,7 @@
"testCustomerAddresses":{"code":200,"message":"OK","body":"{\"addresses\":[{\"id\":3228337350,\"first_name\":\"MobileBuy\",\"last_name\":\"TestBot\",\"phone\":\"1-555-555-5555\",\"company\":\"Shopify Inc.\",\"address1\":\"150 Elgin Street\",\"address2\":\"8th Floor\",\"city\":\"Toledo\",\"province\":null,\"province_code\":null,\"country\":null,\"country_code\":null,\"zip\":\"K1N5T5\"},{\"id\":3228402182,\"first_name\":\"MobileBuy\",\"last_name\":\"TestBot\",\"phone\":\"1-555-555-5555\",\"company\":\"Shopify Inc.\",\"address1\":\"150 Elgin Street\",\"address2\":\"8th Floor\",\"city\":\"Ottawa\",\"province\":null,\"province_code\":null,\"country\":null,\"country_code\":null,\"zip\":\"K1N5T5\"},{\"id\":3228535430,\"first_name\":\"Testy\",\"last_name\":\"McTesterson\",\"phone\":\"1-555-555-5555\",\"company\":\"Shopify Inc.\",\"address1\":\"150 Elgin Street\",\"address2\":\"8th Floor\",\"city\":\"Ottawa\",\"province\":null,\"province_code\":null,\"country\":null,\"country_code\":null,\"zip\":\"K1N5T5\"},{\"id\":3279871622,\"first_name\":\"MobileBuy\",\"last_name\":\"asfas\",\"phone\":null,\"company\":null,\"address1\":\"150 Elgin Street\",\"address2\":\"8th Floor\",\"city\":\"Toledo\",\"province\":\"Ciudad Autónoma de Buenos Aires\",\"province_code\":\"C\",\"country\":\"Argentina\",\"country_code\":\"AR\",\"zip\":\"124124\"}]}"}, "testCustomerAddresses":{"code":200,"message":"OK","body":"{\"addresses\":[{\"id\":3228337350,\"first_name\":\"MobileBuy\",\"last_name\":\"TestBot\",\"phone\":\"1-555-555-5555\",\"company\":\"Shopify Inc.\",\"address1\":\"150 Elgin Street\",\"address2\":\"8th Floor\",\"city\":\"Toledo\",\"province\":null,\"province_code\":null,\"country\":null,\"country_code\":null,\"zip\":\"K1N5T5\"},{\"id\":3228402182,\"first_name\":\"MobileBuy\",\"last_name\":\"TestBot\",\"phone\":\"1-555-555-5555\",\"company\":\"Shopify Inc.\",\"address1\":\"150 Elgin Street\",\"address2\":\"8th Floor\",\"city\":\"Ottawa\",\"province\":null,\"province_code\":null,\"country\":null,\"country_code\":null,\"zip\":\"K1N5T5\"},{\"id\":3228535430,\"first_name\":\"Testy\",\"last_name\":\"McTesterson\",\"phone\":\"1-555-555-5555\",\"company\":\"Shopify Inc.\",\"address1\":\"150 Elgin Street\",\"address2\":\"8th Floor\",\"city\":\"Ottawa\",\"province\":null,\"province_code\":null,\"country\":null,\"country_code\":null,\"zip\":\"K1N5T5\"},{\"id\":3279871622,\"first_name\":\"MobileBuy\",\"last_name\":\"asfas\",\"phone\":null,\"company\":null,\"address1\":\"150 Elgin Street\",\"address2\":\"8th Floor\",\"city\":\"Toledo\",\"province\":\"Ciudad Autónoma de Buenos Aires\",\"province_code\":\"C\",\"country\":\"Argentina\",\"country_code\":\"AR\",\"zip\":\"124124\"}]}"},
"testCustomerAddress1":{"code":200,"message":"OK","body":"{\"address\":{\"id\":3541821574,\"first_name\":\"MobileBuy\",\"last_name\":\"asfas\",\"phone\":null,\"company\":null,\"address1\":\"3892 Streewell Rd.\",\"address2\":null,\"city\":\"Toronto\",\"province\":\"Ontario\",\"province_code\":\"ON\",\"country\":\"Canada\",\"country_code\":\"CA\",\"zip\":\"L8S 2W2\"}}"}, "testCustomerAddress1":{"code":200,"message":"OK","body":"{\"address\":{\"id\":3541821574,\"first_name\":\"MobileBuy\",\"last_name\":\"asfas\",\"phone\":null,\"company\":null,\"address1\":\"3892 Streewell Rd.\",\"address2\":null,\"city\":\"Toronto\",\"province\":\"Ontario\",\"province_code\":\"ON\",\"country\":\"Canada\",\"country_code\":\"CA\",\"zip\":\"L8S 2W2\"}}"},
"testCustomerAddress2":{"code":200,"message":"OK","body":"{\"address\":{\"id\":3541821574,\"first_name\":\"MobileBuy\",\"last_name\":\"asfas\",\"phone\":null,\"company\":null,\"address1\":\"8493 Southwest St.\",\"address2\":null,\"city\":\"Vancouver\",\"province\":\"British Columbia\",\"province_code\":\"BC\",\"country\":\"Canada\",\"country_code\":\"CA\",\"zip\":\"T3G 4D9\"}}"}, "testCustomerAddress2":{"code":200,"message":"OK","body":"{\"address\":{\"id\":3541821574,\"first_name\":\"MobileBuy\",\"last_name\":\"asfas\",\"phone\":null,\"company\":null,\"address1\":\"8493 Southwest St.\",\"address2\":null,\"city\":\"Vancouver\",\"province\":\"British Columbia\",\"province_code\":\"BC\",\"country\":\"Canada\",\"country_code\":\"CA\",\"zip\":\"T3G 4D9\"}}"},
"testCustomerAddressDelete":{"code":204,"message":"OK","body":"{}"} "testCustomerAddressDelete":{"code":204,"message":"OK","body":"{}"},
"testCustomerGetOrders":{"code":200,"message":"OK","body":"{\"orders\":[{\"id\":3005863686,\"order_number\":5222,\"cancel_reason\":null,\"cancelled_at\":null,\"financial_status\":\"pending\",\"fulfillment_status\":\"unfulfilled\",\"processed_at\":\"2016-04-27T06:52:10-04:00\",\"name\":\"#5222\",\"shipping_methods\":[{\"id\":2555842886,\"price\":\"20.00\",\"title\":\"International Shipping\"}],\"payment_details\":null,\"fulfillment_aborted\":false,\"cancelled\":false,\"customer_url\":\"http:\/\/mobilebuysdktestshop.myshopify.com\/account\/orders\/b3769460db411e018c63f10413a0f6ab\",\"order_status_url\":\"https:\/\/checkout.shopify.com\/9575792\/checkouts\/a06200a1519fff9fa699b21f5e5a3356\/thank_you_token?key=71259ee469d206b9e7d844fb899e3a27\",\"discounts_savings\":null,\"refunds\":[],\"billing_address\":{\"id\":4143716294,\"first_name\":\"MobileBuy\",\"last_name\":\"asfas\",\"phone\":null,\"company\":null,\"address1\":\"150 Elgin Street\",\"address2\":\"8th Floor\",\"city\":\"Toledo\",\"province\":\"Ciudad Autónoma de Buenos Aires\",\"province_code\":\"C\",\"country\":\"Argentina\",\"country_code\":\"AR\",\"zip\":\"124124\"},\"shipping_address\":{\"id\":4143716294,\"first_name\":\"MobileBuy\",\"last_name\":\"asfas\",\"phone\":null,\"company\":null,\"address1\":\"150 Elgin Street\",\"address2\":\"8th Floor\",\"city\":\"Toledo\",\"province\":\"Ciudad Autónoma de Buenos Aires\",\"province_code\":\"C\",\"country\":\"Argentina\",\"country_code\":\"AR\",\"zip\":\"124124\"},\"fulfilled_line_items\":[],\"unfulfilled_line_items\":[{\"id\":5443179910,\"key\":5443179910,\"product_id\":2096057987,\"variant_id\":6030684227,\"sku\":\"\",\"vendor\":\"Price and Sons\",\"title\":\"Cauliform Concrete Tablet\",\"variant_title\":\"Tan\",\"taxable\":true,\"requires_shipping\":true,\"price\":\"1855.99\",\"compare_at_price\":null,\"line_price\":\"1855.99\",\"properties\":{},\"quantity\":1,\"grams\":2000,\"fulfillment_service\":\"manual\",\"applied_discounts\":[]}],\"total_price\":\"1875.99\",\"subtotal_price\":\"1855.99\",\"currency\":\"CAD\"}]}"},
"testCustomerGetOrder":{"code":200,"message":"OK","body":"{\"order\":{\"id\":3005863686,\"order_number\":5222,\"cancel_reason\":null,\"cancelled_at\":null,\"financial_status\":\"pending\",\"fulfillment_status\":\"unfulfilled\",\"processed_at\":\"2016-04-27T06:52:10-04:00\",\"name\":\"#5222\",\"shipping_methods\":[{\"id\":2555842886,\"price\":\"20.00\",\"title\":\"International Shipping\"}],\"payment_details\":null,\"fulfillment_aborted\":false,\"cancelled\":false,\"customer_url\":\"http:\/\/mobilebuysdktestshop.myshopify.com\/account\/orders\/b3769460db411e018c63f10413a0f6ab\",\"order_status_url\":\"https:\/\/checkout.shopify.com\/9575792\/checkouts\/a06200a1519fff9fa699b21f5e5a3356\/thank_you_token?key=71259ee469d206b9e7d844fb899e3a27\",\"discounts_savings\":null,\"refunds\":[],\"billing_address\":{\"id\":4143716294,\"first_name\":\"MobileBuy\",\"last_name\":\"asfas\",\"phone\":null,\"company\":null,\"address1\":\"150 Elgin Street\",\"address2\":\"8th Floor\",\"city\":\"Toledo\",\"province\":\"Ciudad Autónoma de Buenos Aires\",\"province_code\":\"C\",\"country\":\"Argentina\",\"country_code\":\"AR\",\"zip\":\"124124\"},\"shipping_address\":{\"id\":4143716294,\"first_name\":\"MobileBuy\",\"last_name\":\"asfas\",\"phone\":null,\"company\":null,\"address1\":\"150 Elgin Street\",\"address2\":\"8th Floor\",\"city\":\"Toledo\",\"province\":\"Ciudad Autónoma de Buenos Aires\",\"province_code\":\"C\",\"country\":\"Argentina\",\"country_code\":\"AR\",\"zip\":\"124124\"},\"fulfilled_line_items\":[],\"unfulfilled_line_items\":[{\"id\":5443179910,\"key\":5443179910,\"product_id\":2096057987,\"variant_id\":6030684227,\"sku\":\"\",\"vendor\":\"Price and Sons\",\"title\":\"Cauliform Concrete Tablet\",\"variant_title\":\"Tan\",\"taxable\":true,\"requires_shipping\":true,\"price\":\"1855.99\",\"compare_at_price\":null,\"line_price\":\"1855.99\",\"properties\":{},\"quantity\":1,\"grams\":2000,\"fulfillment_service\":\"manual\",\"applied_discounts\":[]}],\"total_price\":\"1875.99\",\"subtotal_price\":\"1855.99\",\"currency\":\"CAD\"}}"}
} }
...@@ -64,6 +64,14 @@ typedef void (^BUYDataTokenBlock)(NSString * _Nullable token, NSError * _Nullabl ...@@ -64,6 +64,14 @@ typedef void (^BUYDataTokenBlock)(NSString * _Nullable token, NSError * _Nullabl
*/ */
typedef void (^BUYDataOrdersBlock)(NSArray <BUYOrder*> * _Nullable orders, NSError * _Nullable error); typedef void (^BUYDataOrdersBlock)(NSArray <BUYOrder*> * _Nullable orders, NSError * _Nullable error);
/**
* Return block containing a BUYOrder
*
* @param order A BUYOrder
* @param error An optional NSError
*/
typedef void (^BUYDataOrderBlock)(BUYOrder * _Nullable order, NSError * _Nullable error);
@interface BUYClient (Customers) @interface BUYClient (Customers)
...@@ -190,12 +198,24 @@ typedef void (^BUYDataOrdersBlock)(NSArray <BUYOrder*> * _Nullable orders, NSErr ...@@ -190,12 +198,24 @@ typedef void (^BUYDataOrdersBlock)(NSArray <BUYOrder*> * _Nullable orders, NSErr
* GET /api/customers/:customer_id/orders * GET /api/customers/:customer_id/orders
* Gets orders for a given customer * Gets orders for a given customer
* *
* @param token An auth token retrieved from customer creation or customer login API * @param customerID A customer ID for which to retrieve the order
* @param block (NSArray <BUYOrder*> *orders, NSError *error)
*
* @return The associated BUYRequestOperation
*/
- (BUYRequestOperation *)getOrdersForCustomerWithID:(NSString *)customerID callback:(BUYDataOrdersBlock)block;
/**
* GET /api/customers/:customer_id/orders/:id
* Gets order with a given identifier
*
* @param customerID A customer ID for which to retrieve the order
* @param orderID An order ID to retrieve
* @param block (NSArray <BUYOrder*> *orders, NSError *error) * @param block (NSArray <BUYOrder*> *orders, NSError *error)
* *
* @return The associated BUYRequestOperation * @return The associated BUYRequestOperation
*/ */
- (BUYRequestOperation *)getOrdersForCustomerWithCallback:(BUYDataOrdersBlock)block; - (BUYRequestOperation *)getOrderWithID:(NSNumber *)orderID customerID:(NSString *)customerID callback:(BUYDataOrderBlock)block;
@end @end
......
...@@ -157,9 +157,9 @@ ...@@ -157,9 +157,9 @@
#pragma mark - Orders - #pragma mark - Orders -
- (BUYRequestOperation *)getOrdersForCustomerWithCallback:(BUYDataOrdersBlock)block - (BUYRequestOperation *)getOrdersForCustomerWithID:(NSString *)customerID callback:(BUYDataOrdersBlock)block
{ {
NSURL *url = [self urlForCustomersOrders]; NSURL *url = [self urlForCustomersOrdersWithID:customerID];
return [self getRequestForURL:url completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) { return [self getRequestForURL:url completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
if (json && !error) { if (json && !error) {
NSArray *orders = [self.modelManager ordersWithJSONDictionary:json]; NSArray *orders = [self.modelManager ordersWithJSONDictionary:json];
...@@ -170,6 +170,19 @@ ...@@ -170,6 +170,19 @@
}]; }];
} }
- (BUYRequestOperation *)getOrderWithID:(NSNumber *)orderID customerID:(NSString *)customerID callback:(BUYDataOrderBlock)block
{
NSURL *url = [self urlForCustomersOrdersWithID:customerID orderID:orderID];
return [self getRequestForURL:url completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
if (json && !error) {
BUYOrder *order = [self.modelManager orderWithJSONDictionary:json];
block(order, error);
} else {
block(nil, error);
}
}];
}
#pragma mark - Helpers - #pragma mark - Helpers -
- (BUYRequestOperation *)createTokenForCustomerWithCredentials:(BUYAccountCredentials *)credentials customerJSON:(NSDictionary *)customerJSON callback:(BUYDataCustomerTokenBlock)block - (BUYRequestOperation *)createTokenForCustomerWithCredentials:(BUYAccountCredentials *)credentials customerJSON:(NSDictionary *)customerJSON callback:(BUYDataCustomerTokenBlock)block
......
...@@ -46,10 +46,11 @@ ...@@ -46,10 +46,11 @@
- (NSURL *)urlForCheckoutsUsingGiftCard:(NSNumber *)giftCardID token:(NSString *)token; - (NSURL *)urlForCheckoutsUsingGiftCard:(NSNumber *)giftCardID token:(NSString *)token;
- (NSURL *)urlForCustomers; - (NSURL *)urlForCustomers;
- (NSURL *)urlForCustomersOrders;
- (NSURL *)urlForCustomersToken; - (NSURL *)urlForCustomersToken;
- (NSURL *)urlForCustomersPasswordRecovery; - (NSURL *)urlForCustomersPasswordRecovery;
- (NSURL *)urlForCustomersOrdersWithID:(NSString *)identifier;
- (NSURL *)urlForCustomersOrdersWithID:(NSString *)identifier orderID:(NSNumber *)orderID;
- (NSURL *)urlForCustomersWithID:(NSString *)identifier; - (NSURL *)urlForCustomersWithID:(NSString *)identifier;
- (NSURL *)urlForCustomersActivationWithID:(NSString *)identifier parameters:(NSDictionary *)parameters; - (NSURL *)urlForCustomersActivationWithID:(NSString *)identifier parameters:(NSDictionary *)parameters;
- (NSURL *)urlForCustomersTokenWithID:(NSString *)customerID; - (NSURL *)urlForCustomersTokenWithID:(NSString *)customerID;
......
...@@ -173,11 +173,6 @@ ...@@ -173,11 +173,6 @@
return [[[self urlForAPI] appendPath:@"/customers"] appendExtension]; return [[[self urlForAPI] appendPath:@"/customers"] appendExtension];
} }
- (NSURL *)urlForCustomersOrders
{
return [[[self urlForCustomers] appendPath:@"/orders"] appendExtension];
}
- (NSURL *)urlForCustomersToken - (NSURL *)urlForCustomersToken
{ {
return [[[self urlForCustomers] appendPath:@"/customer_token"] appendExtension]; return [[[self urlForCustomers] appendPath:@"/customer_token"] appendExtension];
...@@ -195,6 +190,16 @@ ...@@ -195,6 +190,16 @@
return [[[self urlForCustomers] appendPath:identifier] appendExtension]; return [[[self urlForCustomers] appendPath:identifier] appendExtension];
} }
- (NSURL *)urlForCustomersOrdersWithID:(NSString *)identifier
{
return [[[self urlForCustomersWithID:identifier] appendPath:@"/orders"] appendExtension];
}
- (NSURL *)urlForCustomersOrdersWithID:(NSString *)identifier orderID:(NSNumber *)orderID
{
return [[[self urlForCustomersOrdersWithID:identifier] appendIdentifier:orderID] appendExtension];
}
- (NSURL *)urlForCustomersActivationWithID:(NSString *)identifier parameters:(NSDictionary *)parameters - (NSURL *)urlForCustomersActivationWithID:(NSString *)identifier parameters:(NSDictionary *)parameters
{ {
return [[[[self urlForCustomersWithID:identifier] appendPath:@"/activate"] appendParameters:parameters] appendExtension]; return [[[[self urlForCustomersWithID:identifier] appendPath:@"/activate"] appendParameters:parameters] appendExtension];
......
...@@ -32,6 +32,7 @@ ...@@ -32,6 +32,7 @@
@interface BUYModelManager (BUYOrder) @interface BUYModelManager (BUYOrder)
- (BUYOrder *)orderWithJSONDictionary:(NSDictionary *)json;
- (NSArray<BUYOrder *> *)ordersWithJSONDictionary:(NSDictionary *)json; - (NSArray<BUYOrder *> *)ordersWithJSONDictionary:(NSDictionary *)json;
@end @end
......
...@@ -68,6 +68,11 @@ ...@@ -68,6 +68,11 @@
@implementation BUYModelManager (BUYOrder) @implementation BUYModelManager (BUYOrder)
- (BUYOrder *)orderWithJSONDictionary:(NSDictionary *)json
{
return (id)[self buy_objectWithEntityName:[BUYOrder entityName] JSONDictionary:json];
}
- (NSArray<BUYOrder *> *)ordersWithJSONDictionary:(NSDictionary *)json - (NSArray<BUYOrder *> *)ordersWithJSONDictionary:(NSDictionary *)json
{ {
NSArray *orders = [json objectForKey:@"orders"]; NSArray *orders = [json objectForKey:@"orders"];
......
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