Commit 558b9be2 by Rune Madsen

"/anywhere/checkouts" is now "/api/checkouts". This transition has been made…

"/anywhere/checkouts" is now "/api/checkouts". This transition has been made using NSURLComponents. Tests have been updated to better match testing of the scheme, host, path and query items from which a NSURLComponents URL is created.
parent 02da0c5e
......@@ -216,57 +216,89 @@
- (void)testProductsInCollectionWithSortOrderCollectionDefault
{
NSURLSessionDataTask *task = [self.client getProductsPage:1 inCollection:@1 sortOrder:BUYCollectionSortCollectionDefault completion:nil];
XCTAssertEqualObjects(task.originalRequest.URL.absoluteString, @"https://test_shop/api/channels/api_key/product_publications.json?collection_id=1&limit=25&page=1&sort_by=collection-default");
XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https");
XCTAssertEqualObjects(task.originalRequest.URL.host, @"test_shop");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/channels/api_key/product_publications.json");
NSSet *requestQueryItems = [NSSet setWithArray:[task.originalRequest.URL.query componentsSeparatedByString:@"&"]];
NSSet *queryItems = [NSSet setWithArray:@[@"collection_id=1", @"limit=25", @"page=1", @"sort_by=collection-default"]];
XCTAssertEqualObjects(requestQueryItems, queryItems);
}
- (void)testProductsInCollectionWithSortOrderBestSelling
{
NSURLSessionDataTask *task = [self.client getProductsPage:1 inCollection:@1 sortOrder:BUYCollectionSortBestSelling completion:nil];
XCTAssertEqualObjects(task.originalRequest.URL.absoluteString, @"https://test_shop/api/channels/api_key/product_publications.json?collection_id=1&limit=25&page=1&sort_by=best-selling");
XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https");
XCTAssertEqualObjects(task.originalRequest.URL.host, @"test_shop");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/channels/api_key/product_publications.json");
NSSet *requestQueryItems = [NSSet setWithArray:[task.originalRequest.URL.query componentsSeparatedByString:@"&"]];
NSSet *queryItems = [NSSet setWithArray:@[@"collection_id=1", @"limit=25", @"page=1", @"sort_by=best-selling"]];
XCTAssertEqualObjects(requestQueryItems, queryItems);
}
- (void)testProductsInCollectionWithSortOrderCreatedAscending
{
NSURLSessionDataTask *task = [self.client getProductsPage:1 inCollection:@1 sortOrder:BUYCollectionSortCreatedAscending completion:nil];
XCTAssertEqualObjects(task.originalRequest.URL.absoluteString, @"https://test_shop/api/channels/api_key/product_publications.json?collection_id=1&limit=25&page=1&sort_by=created-ascending");
XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https");
XCTAssertEqualObjects(task.originalRequest.URL.host, @"test_shop");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/channels/api_key/product_publications.json");
NSSet *requestQueryItems = [NSSet setWithArray:[task.originalRequest.URL.query componentsSeparatedByString:@"&"]];
NSSet *queryItems = [NSSet setWithArray:@[@"collection_id=1", @"limit=25", @"page=1", @"sort_by=created-ascending"]];
XCTAssertEqualObjects(requestQueryItems, queryItems);
}
- (void)testProductsInCollectionWithSortOrderCreatedDescending
{
NSURLSessionDataTask *task = [self.client getProductsPage:1 inCollection:@1 sortOrder:BUYCollectionSortCreatedDescending completion:nil];
XCTAssertEqualObjects(task.originalRequest.URL.absoluteString, @"https://test_shop/api/channels/api_key/product_publications.json?collection_id=1&limit=25&page=1&sort_by=created-descending");
XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https");
XCTAssertEqualObjects(task.originalRequest.URL.host, @"test_shop");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/channels/api_key/product_publications.json");
NSSet *requestQueryItems = [NSSet setWithArray:[task.originalRequest.URL.query componentsSeparatedByString:@"&"]];
NSSet *queryItems = [NSSet setWithArray:@[@"collection_id=1", @"limit=25", @"page=1", @"sort_by=created-descending"]];
XCTAssertEqualObjects(requestQueryItems, queryItems);
}
- (void)testProductsInCollectionWithSortOrderPriceAscending
{
NSURLSessionDataTask *task = [self.client getProductsPage:1 inCollection:@1 sortOrder:BUYCollectionSortPriceAscending completion:nil];
XCTAssertEqualObjects(task.originalRequest.URL.absoluteString, @"https://test_shop/api/channels/api_key/product_publications.json?collection_id=1&limit=25&page=1&sort_by=price-ascending");
XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https");
XCTAssertEqualObjects(task.originalRequest.URL.host, @"test_shop");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/channels/api_key/product_publications.json");
NSSet *requestQueryItems = [NSSet setWithArray:[task.originalRequest.URL.query componentsSeparatedByString:@"&"]];
NSSet *queryItems = [NSSet setWithArray:@[@"collection_id=1", @"limit=25", @"page=1", @"sort_by=price-ascending"]];
XCTAssertEqualObjects(requestQueryItems, queryItems);
}
- (void)testProductsInCollectionWithSortOrderPriceDescending
{
NSURLSessionDataTask *task = [self.client getProductsPage:1 inCollection:@1 sortOrder:BUYCollectionSortPriceDescending completion:nil];
XCTAssertEqualObjects(task.originalRequest.URL.absoluteString, @"https://test_shop/api/channels/api_key/product_publications.json?collection_id=1&limit=25&page=1&sort_by=price-descending");
XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https");
XCTAssertEqualObjects(task.originalRequest.URL.host, @"test_shop");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/channels/api_key/product_publications.json");
NSSet *requestQueryItems = [NSSet setWithArray:[task.originalRequest.URL.query componentsSeparatedByString:@"&"]];
NSSet *queryItems = [NSSet setWithArray:@[@"collection_id=1", @"limit=25", @"page=1", @"sort_by=price-descending"]];
XCTAssertEqualObjects(requestQueryItems, queryItems);
}
- (void)testProductsInCollectionWithSortOrderTitleAscending
{
NSURLSessionDataTask *task = [self.client getProductsPage:1 inCollection:@1 sortOrder:BUYCollectionSortTitleAscending completion:nil];
XCTAssertEqualObjects(task.originalRequest.URL.absoluteString, @"https://test_shop/api/channels/api_key/product_publications.json?collection_id=1&limit=25&page=1&sort_by=title-ascending");
XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https");
XCTAssertEqualObjects(task.originalRequest.URL.host, @"test_shop");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/channels/api_key/product_publications.json");
NSSet *requestQueryItems = [NSSet setWithArray:[task.originalRequest.URL.query componentsSeparatedByString:@"&"]];
NSSet *queryItems = [NSSet setWithArray:@[@"collection_id=1", @"limit=25", @"page=1", @"sort_by=title-ascending"]];
XCTAssertEqualObjects(requestQueryItems, queryItems);
}
- (void)testProductsInCollectionWithSortOrderTitleDescending
{
NSURLSessionDataTask *task = [self.client getProductsPage:1 inCollection:@1 sortOrder:BUYCollectionSortTitleDescending completion:nil];
XCTAssertEqualObjects(task.originalRequest.URL.absoluteString, @"https://test_shop/api/channels/api_key/product_publications.json?collection_id=1&limit=25&page=1&sort_by=title-descending");
XCTAssertEqualObjects(task.originalRequest.URL.scheme, @"https");
XCTAssertEqualObjects(task.originalRequest.URL.host, @"test_shop");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/channels/api_key/product_publications.json");
NSSet *requestQueryItems = [NSSet setWithArray:[task.originalRequest.URL.query componentsSeparatedByString:@"&"]];
NSSet *queryItems = [NSSet setWithArray:@[@"collection_id=1", @"limit=25", @"page=1", @"sort_by=title-descending"]];
XCTAssertEqualObjects(requestQueryItems, queryItems);
}
@end
......@@ -110,9 +110,9 @@ NSString * const BUYVersionString = @"1.2.3";
- (NSURLSessionDataTask *)getShop:(BUYDataShopBlock)block
{
NSString *url = [NSString stringWithFormat:@"https://%@/meta.json", _shopDomain];
NSURLComponents *shopComponents = [self URLComponentsForShop];
return [self getRequestForURL:url completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
return [self getRequestForURL:shopComponents.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
BUYShop *shop = nil;
if (json && error == nil) {
shop = [[BUYShop alloc] initWithDictionary:json];
......@@ -123,9 +123,11 @@ NSString * const BUYVersionString = @"1.2.3";
- (NSURLSessionDataTask *)getProductsPage:(NSUInteger)page completion:(BUYDataProductListBlock)block
{
NSString *url = [NSString stringWithFormat:@"https://%@/api/channels/%@/product_publications.json?limit=%lu&page=%lu", self.shopDomain, self.channelId, (unsigned long)self.pageSize, (unsigned long)page];
NSURLComponents *components = [self URLComponentsForChannelsWithEndPoint:@"product_publications.json"
queryItems:@{@"limit" : [NSString stringWithFormat:@"%lu", (unsigned long)self.pageSize],
@"page" : [NSString stringWithFormat:@"%lu", (unsigned long)page]}];
return [self getRequestForURL:url completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
return [self getRequestForURL:components.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSArray *products = nil;
if (json && error == nil) {
......@@ -151,8 +153,10 @@ NSString * const BUYVersionString = @"1.2.3";
- (NSURLSessionDataTask *)getProductsByIds:(NSArray *)productIds completion:(BUYDataProductsBlock)block
{
NSString *url = [NSString stringWithFormat:@"https://%@/api/channels/%@/product_publications.json?product_ids=%@", self.shopDomain, self.channelId, [productIds componentsJoinedByString:@","]];
return [self getRequestForURL:url completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSURLComponents *components = [self URLComponentsForChannelsWithEndPoint:@"product_publications.json"
queryItems:@{@"product_ids" : [productIds componentsJoinedByString:@","]}];
return [self getRequestForURL:components.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSArray *products = nil;
if (json && error == nil) {
......@@ -167,9 +171,9 @@ NSString * const BUYVersionString = @"1.2.3";
- (NSURLSessionDataTask *)getCollections:(BUYDataCollectionsBlock)block
{
NSString *url = [NSString stringWithFormat:@"https://%@/api/channels/%@/collection_publications.json", self.shopDomain, self.channelId];
NSURLComponents *components = [self URLComponentsForChannelsWithEndPoint:@"collection_publications.json" queryItems:nil];
return [self getRequestForURL:url completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
return [self getRequestForURL:components.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSArray *collections = nil;
if (json && error == nil) {
......@@ -188,14 +192,13 @@ NSString * const BUYVersionString = @"1.2.3";
{
NSURLSessionDataTask *task = nil;
if (collectionId) {
NSMutableArray *parameters = [NSMutableArray array];
[parameters addObject:[NSString stringWithFormat:@"collection_id=%lu", collectionId.longValue]];
[parameters addObject:[NSString stringWithFormat:@"limit=%lu", (unsigned long)self.pageSize]];
[parameters addObject:[NSString stringWithFormat:@"page=%lu", (unsigned long)page]];
[parameters addObject:[NSString stringWithFormat:@"sort_by=%@", [BUYCollection sortOrderParameterForCollectionSort:sortOrder]]];
NSString *url = [NSString stringWithFormat:@"https://%@/api/channels/%@/product_publications.json?%@", self.shopDomain, self.channelId, [parameters componentsJoinedByString:@"&"]];
NSURLComponents *components = [self URLComponentsForChannelsWithEndPoint:@"product_publications.json"
queryItems:@{@"collection_id" : [NSString stringWithFormat:@"%lu", collectionId.longValue],
@"limit" : [NSString stringWithFormat:@"%lu", (unsigned long)self.pageSize],
@"page" : [NSString stringWithFormat:@"%lu", (unsigned long)page],
@"sort_by" : [BUYCollection sortOrderParameterForCollectionSort:sortOrder]}];
task = [self getRequestForURL:url completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
task = [self getRequestForURL:components.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSArray *products = nil;
if (json && error == nil) {
......@@ -223,6 +226,63 @@ NSString * const BUYVersionString = @"1.2.3";
return error;
}
#pragma mark - URL Components
- (NSURLComponents *)URLComponentsForChannelsWithEndPoint:(NSString *)endPoint queryItems:(NSDictionary*)queryItems
{
return [self URLComponentsForAPIPath:[NSString stringWithFormat:@"channels/%@", self.channelId] endPoint:endPoint queryItems:queryItems];
}
- (NSURLComponents *)URLComponentsForCheckoutsWithToken:(NSString *)checkoutToken endPoint:(NSString *)endPoint queryItems:(NSDictionary*)queryItems
{
NSMutableString *apiPath = [NSMutableString stringWithString:@"checkouts"];
if (checkoutToken) {
[apiPath appendFormat:@"/%@", checkoutToken];
} else {
[apiPath appendString:@".json"];
}
return [self URLComponentsForAPIPath:[apiPath copy] endPoint:endPoint queryItems:queryItems];
}
- (NSURLComponents *)URLComponentsForAPIPath:(NSString *)apiPath endPoint:(NSString *)endPoint queryItems:(NSDictionary*)queryItems
{
NSMutableArray *pathComponents = [NSMutableArray array];
[pathComponents addObject:@"api"];
[pathComponents addObject:apiPath];
if (endPoint) {
[pathComponents addObject:endPoint];
}
return [self URLComponentsForPathComponents:pathComponents queryItems:queryItems];
}
- (NSURLComponents *)URLComponentsForShop
{
return [self URLComponentsForPathComponents:@[@"meta.json"] queryItems:nil];
}
- (NSURLComponents *)URLComponentsForPathComponents:(NSArray*)pathComponents queryItems:(NSDictionary*)queryItems
{
NSURLComponents *components = [[NSURLComponents alloc] init];
components.scheme = @"https";
components.host = self.shopDomain;
components.path = [NSString stringWithFormat:@"/%@", [pathComponents componentsJoinedByString:@"/"]];
components.queryItems = [self queryItemsWithNamesAndValues:queryItems];
return components;
}
- (NSArray*)queryItemsWithNamesAndValues:(NSDictionary*)namesAndValues
{
if (namesAndValues) {
NSMutableArray *queryItems = [NSMutableArray array];
for (NSString *key in [namesAndValues allKeys]) {
[queryItems addObject:[[NSURLQueryItem alloc] initWithName:key value:namesAndValues[key]]];
}
return [queryItems copy];
} else {
return nil;
}
}
#pragma mark - Checkout
- (void)handleCheckoutResponse:(NSDictionary *)json error:(NSError *)error block:(BUYDataCheckoutBlock)block
......@@ -271,7 +331,9 @@ NSString * const BUYVersionString = @"1.2.3";
NSData *data = [NSJSONSerialization dataWithJSONObject:checkoutJSON options:0 error:&error];
if (data && error == nil) {
task = [self postRequestForURL:[NSString stringWithFormat:@"https://%@/anywhere/checkouts.json", _shopDomain] body:data completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSURLComponents *components = [self URLComponentsForCheckoutsWithToken:nil endPoint:nil queryItems:nil];
task = [self postRequestForURL:components.URL body:data completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
[self handleCheckoutResponse:json error:error block:block];
}];
}
......@@ -287,7 +349,13 @@ NSString * const BUYVersionString = @"1.2.3";
}
else {
BUYGiftCard *giftCard = [[BUYGiftCard alloc] initWithDictionary:@{ @"code" : giftCardCode }];
task = [self postRequestForURL:[NSString stringWithFormat:@"https://%@/anywhere/checkouts/%@/gift_cards.json", _shopDomain, checkout.token] object:giftCard completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSURLComponents *components = [self URLComponentsForCheckoutsWithToken:checkout.token
endPoint:@"gift_cards.json"
queryItems:nil];
task = [self postRequestForURL:components.URL
object:giftCard
completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
if (error == nil) {
[self updateCheckout:checkout withGiftCardDictionary:json[@"gift_card"] addingGiftCard:YES];
}
......@@ -302,7 +370,8 @@ NSString * const BUYVersionString = @"1.2.3";
{
NSURLSessionDataTask *task = nil;
if (giftCard.identifier) {
task = [self deleteRequestForURL:[NSString stringWithFormat:@"https://%@/anywhere/checkouts/%@/gift_cards/%@.json", _shopDomain, checkout.token, giftCard.identifier] completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSURLComponents *components = [self URLComponentsForCheckoutsWithToken:checkout.token endPoint:[NSString stringWithFormat:@"gift_cards/%@.json", giftCard.identifier] queryItems:nil];
task = [self deleteRequestForURL:components.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
if (error == nil) {
[self updateCheckout:checkout withGiftCardDictionary:json[@"gift_card"] addingGiftCard:NO];
}
......@@ -327,6 +396,7 @@ NSString * const BUYVersionString = @"1.2.3";
}
checkout.giftCards = [giftCardArray copy];
checkout.paymentDue = [NSDecimalNumber buy_decimalNumberFromJSON:giftCardDictionary[@"checkout"][@"payment_due"]];
// Marking the checkout as clean. The properties we have updated above we don't need to re-sync with Shopify.
// There's also an issue with gift cards where syncing the gift card JSON won't work since the update endpoint
// doesn't accept the gift card without a gift card code (which we do not have).
......@@ -335,7 +405,8 @@ NSString * const BUYVersionString = @"1.2.3";
- (NSURLSessionDataTask *)getCheckout:(BUYCheckout *)checkout completion:(BUYDataCheckoutBlock)block
{
return [self getRequestForURL:[NSString stringWithFormat:@"https://%@/anywhere/checkouts/%@.json", _shopDomain, checkout.token] completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSURLComponents *components = [self URLComponentsForCheckoutsWithToken:checkout.token endPoint:nil queryItems:nil];
return [self getRequestForURL:components.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
[self handleCheckoutResponse:json error:error block:block];
}];
}
......@@ -347,7 +418,8 @@ NSString * const BUYVersionString = @"1.2.3";
NSURLSessionDataTask *task = nil;
if ([checkout hasToken]) {
task = [self patchRequestForURL:[NSString stringWithFormat:@"https://%@/anywhere/checkouts/%@.json", _shopDomain, checkout.token] body:data completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSURLComponents *components = [self URLComponentsForCheckoutsWithToken:checkout.token endPoint:nil queryItems:nil];
task = [self patchRequestForURL:components.URL body:data completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
[self handleCheckoutResponse:json error:error block:block];
}];
}
......@@ -412,7 +484,8 @@ NSString * const BUYVersionString = @"1.2.3";
- (NSURLSessionDataTask *)checkoutCompletionRequestWithCheckout:(BUYCheckout *)checkout body:(NSData *)body completion:(BUYDataCheckoutBlock)block
{
return [self postRequestForURL:[NSString stringWithFormat:@"https://%@/anywhere/checkouts/%@/complete.json", _shopDomain, checkout.token] body:body completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSURLComponents *components = [self URLComponentsForCheckoutsWithToken:checkout.token endPoint:@"complete.json" queryItems:nil];
return [self postRequestForURL:components.URL body:body completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
[self handleCheckoutResponse:json error:error block:block];
}];
}
......@@ -452,7 +525,8 @@ NSString * const BUYVersionString = @"1.2.3";
- (NSURLSessionDataTask *)getCompletionStatusOfCheckoutToken:(NSString *)token completion:(BUYDataCheckoutStatusBlock)block
{
return [self getRequestForURL:[NSString stringWithFormat:@"https://%@/anywhere/checkouts/%@/processing.json", _shopDomain, token] completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSURLComponents *components = [self URLComponentsForCheckoutsWithToken:token endPoint:@"processing.json" queryItems:nil];
return [self getRequestForURL:components.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSInteger statusCode = [(NSHTTPURLResponse *)response statusCode];
block([BUYClient statusForStatusCode:statusCode error:error], error);
}];
......@@ -464,7 +538,8 @@ NSString * const BUYVersionString = @"1.2.3";
{
NSURLSessionDataTask *task = nil;
if ([checkout hasToken]) {
task = [self getRequestForURL:[NSString stringWithFormat:@"https://%@/anywhere/checkouts/%@/shipping_rates.json?checkout", _shopDomain, checkout.token] completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSURLComponents *components = [self URLComponentsForCheckoutsWithToken:checkout.token endPoint:@"shipping_rates.json?checkout" queryItems:@{ }];
task = [self getRequestForURL:components.URL completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSArray *shippingRates = nil;
if (error == nil && json) {
shippingRates = [BUYShippingRate convertJSONArray:json[@"shipping_rates"]];
......@@ -552,7 +627,7 @@ NSString * const BUYVersionString = @"1.2.3";
return [[BUYError alloc] initWithDomain:kShopifyError code:statusCode userInfo:errorDictionary];
}
- (NSURLSessionDataTask *)requestForURL:(NSString *)url method:(NSString *)method object:(id <BUYSerializable>)object completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
- (NSURLSessionDataTask *)requestForURL:(NSURL *)url method:(NSString *)method object:(id <BUYSerializable>)object completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
{
NSDictionary *json = [object jsonDictionaryForCheckout];
NSError *error = nil;
......@@ -569,9 +644,9 @@ NSString * const BUYVersionString = @"1.2.3";
[task resume];
}
- (NSURLSessionDataTask *)requestForURL:(NSString *)url method:(NSString *)method body:(NSData *)body completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
- (NSURLSessionDataTask *)requestForURL:(NSURL *)url method:(NSString *)method body:(NSData *)body completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
{
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:url]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url];
request.HTTPBody = body;
[request addValue:[self authorizationHeader] forHTTPHeaderField:@"Authorization"];
......@@ -609,7 +684,7 @@ NSString * const BUYVersionString = @"1.2.3";
- (NSURLSessionDataTask *)postPaymentRequestWithCheckout:(BUYCheckout *)checkout body:(NSData *)body completion:(BUYDataCreditCardBlock)block
{
return [self requestForURL:[checkout.paymentURL absoluteString] method:kPOST body:body completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
return [self requestForURL:checkout.paymentURL method:kPOST body:body completionHandler:^(NSDictionary *json, NSURLResponse *response, NSError *error) {
NSString *paymentSessionId = nil;
if (error == nil) {
paymentSessionId = json[@"id"];
......@@ -619,32 +694,32 @@ NSString * const BUYVersionString = @"1.2.3";
}];
}
- (NSURLSessionDataTask *)getRequestForURL:(NSString *)url completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
- (NSURLSessionDataTask *)getRequestForURL:(NSURL *)url completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
{
return [self requestForURL:url method:kGET body:nil completionHandler:completionHandler];
}
- (NSURLSessionDataTask *)postRequestForURL:(NSString *)url object:(id <BUYSerializable>)object completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
- (NSURLSessionDataTask *)postRequestForURL:(NSURL *)url object:(id <BUYSerializable>)object completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
{
return [self requestForURL:url method:kPOST object:object completionHandler:completionHandler];
}
- (NSURLSessionDataTask *)postRequestForURL:(NSString *)url body:(NSData *)body completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
- (NSURLSessionDataTask *)postRequestForURL:(NSURL *)url body:(NSData *)body completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
{
return [self requestForURL:url method:kPOST body:body completionHandler:completionHandler];
}
- (NSURLSessionDataTask *)patchRequestForURL:(NSString *)url object:(id <BUYSerializable>)object completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
- (NSURLSessionDataTask *)patchRequestForURL:(NSURL *)url object:(id <BUYSerializable>)object completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
{
return [self requestForURL:url method:kPATCH object:object completionHandler:completionHandler];
}
- (NSURLSessionDataTask *)patchRequestForURL:(NSString *)url body:(NSData *)body completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
- (NSURLSessionDataTask *)patchRequestForURL:(NSURL *)url body:(NSData *)body completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
{
return [self requestForURL:url method:kPATCH body:body completionHandler:completionHandler];
}
- (NSURLSessionDataTask *)deleteRequestForURL:(NSString *)url completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
- (NSURLSessionDataTask *)deleteRequestForURL:(NSURL *)url completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
{
return [self requestForURL:url method:kDELETE body:nil completionHandler:completionHandler];
}
......
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