Commit 1f7d1f02 by Dima Bart

Remove unused imports, cleanup macro definitions, various cleanup.

parent c502aa4c
......@@ -34,17 +34,12 @@
#import "BUYShopifyErrorCodes.h"
#import "BUYAccountCredentials.h"
#import "BUYClient+Customers.h"
#import "BUYClient+Internal.h"
#import "BUYApplePayToken.h"
#import "BUYApplePayTestToken.h"
NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
@interface BUYClient ()
+ (BUYStatus)statusForStatusCode:(NSUInteger)statusCode error:(NSError *)error;
@end
@interface BUYClient_Test : BUYClient
@end
......@@ -169,22 +164,22 @@ NSString * const BUYFakeCustomerToken = @"dsfasdgafdg";
- (void)testStatusCodeConversions
{
BUYStatus status = [BUYClient statusForStatusCode:412 error:nil];
BUYStatus status = [self.client statusForStatusCode:412 error:nil];
XCTAssertEqual(BUYStatusPreconditionFailed, status);
status = [BUYClient statusForStatusCode:404 error:nil];
status = [self.client statusForStatusCode:404 error:nil];
XCTAssertEqual(BUYStatusNotFound, status);
status = [BUYClient statusForStatusCode:0 error:[NSError errorWithDomain:@"" code:-1 userInfo:nil]];
status = [self.client statusForStatusCode:0 error:[NSError errorWithDomain:@"" code:-1 userInfo:nil]];
XCTAssertEqual(BUYStatusFailed, status);
status = [BUYClient statusForStatusCode:424 error:nil];
status = [self.client statusForStatusCode:424 error:nil];
XCTAssertEqual(BUYStatusFailed, status);
status = [BUYClient statusForStatusCode:202 error:nil];
status = [self.client statusForStatusCode:202 error:nil];
XCTAssertEqual(BUYStatusProcessing, status);
status = [BUYClient statusForStatusCode:200 error:nil];
status = [self.client statusForStatusCode:200 error:nil];
XCTAssertEqual(BUYStatusComplete, status);
}
......
......@@ -348,7 +348,7 @@
9A0B0C6E1CEB4D300037D68F /* BUYClient+Storefront.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0C6B1CEB4D300037D68F /* BUYClient+Storefront.m */; };
9A0B0C6F1CEB4D300037D68F /* BUYClient+Storefront.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0C6B1CEB4D300037D68F /* BUYClient+Storefront.m */; };
9A0B0C721CEB52B90037D68F /* BUYClient+Checkout.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A0B0C701CEB52B90037D68F /* BUYClient+Checkout.h */; settings = {ATTRIBUTES = (Public, ); }; };
9A0B0C731CEB52B90037D68F /* BUYClient+Checkout.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A0B0C701CEB52B90037D68F /* BUYClient+Checkout.h */; };
9A0B0C731CEB52B90037D68F /* BUYClient+Checkout.h in Headers */ = {isa = PBXBuildFile; fileRef = 9A0B0C701CEB52B90037D68F /* BUYClient+Checkout.h */; settings = {ATTRIBUTES = (Public, ); }; };
9A0B0C741CEB52B90037D68F /* BUYClient+Checkout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0C711CEB52B90037D68F /* BUYClient+Checkout.m */; };
9A0B0C751CEB52B90037D68F /* BUYClient+Checkout.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A0B0C711CEB52B90037D68F /* BUYClient+Checkout.m */; };
9A102D1B1CDD1F960026CC43 /* BUYErrorTests.m in Sources */ = {isa = PBXBuildFile; fileRef = 9A102D1A1CDD1F960026CC43 /* BUYErrorTests.m */; };
......
......@@ -30,6 +30,7 @@ NS_ASSUME_NONNULL_BEGIN
@class BUYCheckout;
@class BUYShippingRate;
@class BUYGiftCard;
@class BUYCreditCard;
@protocol BUYPaymentToken;
......
......@@ -148,7 +148,7 @@
}];
}
else {
block(nil, [NSError errorWithDomain:kShopifyError code:BUYShopifyError_InvalidCustomerToken userInfo:nil]);
block(nil, [NSError errorWithDomain:BUYShopifyErrorDomain code:BUYShopifyError_InvalidCustomerToken userInfo:nil]);
return nil;
}
}
......
......@@ -27,7 +27,9 @@
#import "BUYClient.h"
#import "BUYSerializable.h"
extern NSString *const kShopifyError;
static NSString * const BUYShopifyErrorDomain = @"shopify";
static NSString * const BUYClientVersionString = @"1.3";
static NSString * const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token";
@interface BUYClient (Internal)
......
......@@ -84,7 +84,7 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
block(products[0], error);
} else {
if (!error) {
error = [NSError errorWithDomain:kShopifyError code:BUYShopifyError_InvalidProductID userInfo:@{ NSLocalizedDescriptionKey : @"Product ID is not valid. Confirm the product ID on your shop's admin and also ensure that the visibility is on for the Mobile App channel." }];
error = [NSError errorWithDomain:BUYShopifyErrorDomain code:BUYShopifyError_InvalidProductID userInfo:@{ NSLocalizedDescriptionKey : @"Product ID is not valid. Confirm the product ID on your shop's admin and also ensure that the visibility is on for the Mobile App channel." }];
}
block(nil, error);
}
......@@ -106,7 +106,7 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
products = [self.modelManager insertProductsWithJSONArray:json[BUYProductsKey]];
}
if (!error && products.count == 0) {
error = [NSError errorWithDomain:kShopifyError code:BUYShopifyError_InvalidProductID userInfo:@{ NSLocalizedDescriptionKey : @"Product IDs are not valid. Confirm the product IDs on your shop's admin and also ensure that the visibility is on for the Mobile App channel." }];
error = [NSError errorWithDomain:BUYShopifyErrorDomain code:BUYShopifyError_InvalidProductID userInfo:@{ NSLocalizedDescriptionKey : @"Product IDs are not valid. Confirm the product IDs on your shop's admin and also ensure that the visibility is on for the Mobile App channel." }];
}
block(products, error);
}];
......
......@@ -26,20 +26,8 @@
@import Foundation;
@class BUYAccountCredentials;
@class BUYCart;
@class BUYCheckout;
@class BUYCreditCard;
@class BUYGiftCard;
@class BUYProduct;
@class BUYProductVariant;
@class BUYShop;
@class BUYCollection;
@class BUYOrder;
@class BUYModelManager;
@protocol BUYPaymentToken;
/**
* The sort order for products in a collection
*/
......@@ -78,10 +66,6 @@ typedef NS_ENUM(NSUInteger, BUYCollectionSort) {
BUYCollectionSortCreatedDescending
};
extern NSString * _Nonnull const BUYVersionString;
extern NSString * _Nonnull const BUYClientCustomerAccessToken;
/**
* A BUYStatus is associated with the completion of an enqueued job on Shopify.
* BUYStatus is equal is HTTP status codes returned from the server
......@@ -204,5 +188,6 @@ NS_ASSUME_NONNULL_BEGIN
*/
- (void)enableApplePayWithMerchantId:(NSString *)merchantId NS_DEPRECATED_IOS(8_0, 9_0, "Set the merchantId on a `BUYViewController` subclass instead");
@end
NS_ASSUME_NONNULL_END
@end
......@@ -25,42 +25,10 @@
//
#import "BUYClient+Internal.h"
#import "BUYClient+Routing.h"
#import "BUYAssert.h"
#import "BUYAddress.h"
#import "BUYCart.h"
#import "BUYCheckout.h"
#import "BUYCreditCard.h"
#import "BUYCreditCardToken.h"
#import "BUYCollection.h"
#import "BUYError.h"
#import "BUYGiftCard.h"
#import "BUYModelManager.h"
#import "BUYOrder.h"
#import "BUYProduct.h"
#import "BUYShippingRate.h"
#import "BUYShop.h"
#import "BUYShopifyErrorCodes.h"
#import "NSDecimalNumber+BUYAdditions.h"
#import "NSDictionary+BUYAdditions.h"
#import "NSURLComponents+BUYAdditions.h"
#define kGET @"GET"
#define kPOST @"POST"
#define kPATCH @"PATCH"
#define kPUT @"PUT"
#define kDELETE @"DELETE"
#define kJSONType @"application/json"
#define kMinSuccessfulStatusCode 200
#define kMaxSuccessfulStatusCode 299
NSString * const BUYVersionString = @"1.3";
NSString *const kShopifyError = @"shopify";
NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token";
static NSString * const BUYClientJSONMimeType = @"application/json";
@interface BUYClient () <NSURLSessionDelegate>
......@@ -110,7 +78,7 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
NSString *bundleIdentifier = [[NSBundle mainBundle] bundleIdentifier];
config.HTTPAdditionalHeaders = @{@"User-Agent": [NSString stringWithFormat:@"Mobile Buy SDK iOS/%@/%@", BUYVersionString, bundleIdentifier]};
config.HTTPAdditionalHeaders = @{@"User-Agent": [NSString stringWithFormat:@"Mobile Buy SDK iOS/%@/%@", BUYClientVersionString, bundleIdentifier]};
return [NSURLSession sessionWithConfiguration:config delegate:self delegateQueue:nil];
}
......@@ -146,8 +114,8 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
- (NSError *)errorFromJSON:(NSDictionary *)json response:(NSURLResponse *)response
{
NSInteger statusCode = [((NSHTTPURLResponse *) response) statusCode];
if (statusCode < kMinSuccessfulStatusCode || statusCode > kMaxSuccessfulStatusCode) {
return [[NSError alloc] initWithDomain:kShopifyError code:statusCode userInfo:json];
if ((int)(statusCode / 100.0) != 2) { // If not a 2xx response code
return [[NSError alloc] initWithDomain:BUYShopifyErrorDomain code:statusCode userInfo:json];
}
return nil;
}
......@@ -156,27 +124,27 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
- (NSURLSessionDataTask *)getRequestForURL:(NSURL *)url completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
{
return [self requestForURL:url method:kGET object:nil completionHandler:completionHandler];
return [self requestForURL:url method:@"GET" object:nil completionHandler: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];
return [self requestForURL:url method:@"POST" object:object completionHandler:completionHandler];
}
- (NSURLSessionDataTask *)putRequestForURL:(NSURL *)url object:(id<BUYSerializable>)object completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
{
return [self requestForURL:url method:kPUT object:object completionHandler:completionHandler];
return [self requestForURL:url method:@"PUT" object:object completionHandler: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];
return [self requestForURL:url method:@"PATCH" object:object completionHandler:completionHandler];
}
- (NSURLSessionDataTask *)deleteRequestForURL:(NSURL *)url completionHandler:(void (^)(NSDictionary *json, NSURLResponse *response, NSError *error))completionHandler
{
return [self requestForURL:url method:kDELETE object:nil completionHandler:completionHandler];
return [self requestForURL:url method:@"DELETE" object:nil completionHandler:completionHandler];
}
#pragma mark - Generic Requests
......@@ -200,8 +168,8 @@ NSString *const BUYClientCustomerAccessToken = @"X-Shopify-Customer-Access-Token
}
[request addValue:[self authorizationHeader] forHTTPHeaderField:@"Authorization"];
[request addValue:kJSONType forHTTPHeaderField:@"Content-Type"];
[request addValue:kJSONType forHTTPHeaderField:@"Accept"];
[request addValue:BUYClientJSONMimeType forHTTPHeaderField:@"Content-Type"];
[request addValue:BUYClientJSONMimeType forHTTPHeaderField:@"Accept"];
if (self.customerToken) {
[request addValue:self.customerToken forHTTPHeaderField:BUYClientCustomerAccessToken];
......
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