Commit 22c35e5a by Dima Bart

Migrate to App Extensions API.

- switch from channelID to appID
- adjust API endpoints for products and collections
- adjust mocked responses
parent 8f6e4bcc
......@@ -31,7 +31,7 @@
#warning - Enter your shop domain and API Key
#define SHOP_DOMAIN @""
#define API_KEY @""
#define CHANNEL_ID @""
#define APP_ID @""
@interface CollectionListViewController ()
......@@ -51,7 +51,7 @@
self.client = [[BUYClient alloc] initWithShopDomain:SHOP_DOMAIN
apiKey:API_KEY
channelId:CHANNEL_ID];
appId:APP_ID];
[[UIApplication sharedApplication] setNetworkActivityIndicatorVisible:YES];
[self.client getCollections:^(NSArray *collections, NSError *error) {
......
......@@ -62,9 +62,9 @@
{
self.shopDomain = BUYShopDomain_Placeholder;
self.apiKey = BUYAPIKey_Placeholder;
self.channelId = BUYChannelId_Placeholder;
self.appId = BUYAppId_Placeholder;
self.client = [[BUYClient_Test alloc] initWithShopDomain:self.shopDomain apiKey:self.apiKey channelId:self.channelId];
self.client = [[BUYClient_Test alloc] initWithShopDomain:self.shopDomain apiKey:self.apiKey appId:self.appId];
}
- (NSData *)dataForCartFromClient:(BUYClient *)client
......@@ -89,9 +89,8 @@
NSDictionary *dict = @{@"checkout":
@{@"line_items": @[],
@"channel_id": self.channelId,
@"source_name": @"mobile_app",
@"source_identifier": self.client.channelId,
@"source_identifier": self.client.appId,
@"marketing_attribution":@{@"medium": @"iOS", @"source": self.client.applicationName}}};
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:data options:0 error:nil];
......@@ -230,7 +229,7 @@
XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET");
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");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/apps/api_key/product_listings.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);
......@@ -242,7 +241,7 @@
XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET");
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");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/apps/api_key/product_listings.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);
......@@ -254,7 +253,7 @@
XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET");
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");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/apps/api_key/product_listings.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);
......@@ -266,7 +265,7 @@
XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET");
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");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/apps/api_key/product_listings.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);
......@@ -278,7 +277,7 @@
XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET");
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");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/apps/api_key/product_listings.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);
......@@ -290,7 +289,7 @@
XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET");
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");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/apps/api_key/product_listings.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);
......@@ -302,7 +301,7 @@
XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET");
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");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/apps/api_key/product_listings.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);
......@@ -314,7 +313,7 @@
XCTAssertEqualObjects(task.originalRequest.HTTPMethod, @"GET");
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");
XCTAssertEqualObjects(task.originalRequest.URL.path, @"/api/apps/api_key/product_listings.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);
......
......@@ -29,13 +29,13 @@
extern NSString * const BUYShopDomain_Placeholder;
extern NSString * const BUYAPIKey_Placeholder;
extern NSString * const BUYChannelId_Placeholder;
extern NSString * const BUYAppId_Placeholder;
@interface BUYClientTestBase : XCTestCase
@property (nonatomic, strong) NSString *shopDomain;
@property (nonatomic, strong) NSString *apiKey;
@property (nonatomic, strong) NSString *channelId;
@property (nonatomic, strong) NSString *appId;
@property (nonatomic, strong) NSString *merchantId;
@property (nonatomic, strong) NSString *giftCardCode;
@property (nonatomic, strong) NSString *giftCardCode2;
......
......@@ -29,7 +29,7 @@
NSString * const BUYShopDomain_Placeholder = @"test_shop";
NSString * const BUYAPIKey_Placeholder = @"channel_id";
NSString * const BUYChannelId_Placeholder = @"api_key";
NSString * const BUYAppId_Placeholder = @"api_key";
@implementation BUYClientTestBase
......@@ -50,7 +50,7 @@ NSString * const BUYChannelId_Placeholder = @"api_key";
NSDictionary *environment = [[NSProcessInfo processInfo] environment];
self.shopDomain = environment[kBUYTestDomain] ?: jsonConfig[kBUYTestDomain];
self.apiKey = environment[kBUYTestAPIKey] ?: jsonConfig[kBUYTestAPIKey];
self.channelId = environment[kBUYTestChannelId] ?: jsonConfig[kBUYTestChannelId];
self.appId = environment[kBUYTestAppId] ?: jsonConfig[kBUYTestAppId];
self.merchantId = environment[kBUYTestMerchantId] ?: jsonConfig[kBUYTestMerchantId];
NSDictionary *giftCards = jsonConfig[@"gift_cards"];
......@@ -75,7 +75,7 @@ NSString * const BUYChannelId_Placeholder = @"api_key";
self.shopDomain = BUYShopDomain_Placeholder;
self.apiKey = BUYAPIKey_Placeholder;
self.channelId = BUYChannelId_Placeholder;
self.appId = BUYAppId_Placeholder;
self.giftCardCode = @"rd11";
self.giftCardCode2 = @"rd25";
......@@ -84,12 +84,12 @@ NSString * const BUYChannelId_Placeholder = @"api_key";
self.giftCardCodeExpired = @"gibberish";
}
self.client = [[BUYClient alloc] initWithShopDomain:self.shopDomain apiKey:self.apiKey channelId:self.channelId];
self.client = [[BUYClient alloc] initWithShopDomain:self.shopDomain apiKey:self.apiKey appId:self.appId];
}
- (BOOL)shouldUseMocks
{
if (!self.shopDomain.length && !self.apiKey.length && !self.channelId.length) {
if (!self.shopDomain.length && !self.apiKey.length && !self.appId.length) {
_shouldUseMocks = YES;
}
......
......@@ -902,7 +902,7 @@
return [OHHTTPStubsResponse responseWithKey:@"testInvalidIntegrationBadShopUrl_0"];
}];
self.client = [[BUYClient alloc] initWithShopDomain:@"asdfdsasdfdsasdfdsadsfowinfaoinfw.myshopify.com" apiKey:self.apiKey channelId:nil];
self.client = [[BUYClient alloc] initWithShopDomain:@"asdfdsasdfdsasdfdsadsfowinfaoinfw.myshopify.com" apiKey:self.apiKey appId:nil];
[self.client createCheckout:_checkout completion:^(BUYCheckout *checkout, NSError *error) {
XCTAssertNotNil(error);
XCTAssertEqualObjects(error.domain, @"shopify");
......@@ -1163,7 +1163,7 @@
} withStubResponse:^OHHTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
return [OHHTTPStubsResponse responseWithKey:@"testInvalidIntegrationBadChannelId_0"];
}];
BUYClient *badClient = [[BUYClient alloc] initWithShopDomain:self.shopDomain apiKey:self.apiKey channelId:@"asdvfdbfdgasfgdsfg"];
BUYClient *badClient = [[BUYClient alloc] initWithShopDomain:self.shopDomain apiKey:self.apiKey appId:@"asdvfdbfdgasfgdsfg"];
XCTAssertFalse([badClient testIntegrationWithMerchantId:nil]);
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest * _Nonnull request) {
......@@ -1171,7 +1171,7 @@
} withStubResponse:^OHHTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
return [OHHTTPStubsResponse responseWithKey:@"testInvalidIntegrationBadApiKey_0"];
}];
badClient = [[BUYClient alloc] initWithShopDomain:self.shopDomain apiKey:@"sadgsefgsdfgsdfgsdfg" channelId:self.channelId];
badClient = [[BUYClient alloc] initWithShopDomain:self.shopDomain apiKey:@"sadgsefgsdfgsdfgsdfg" appId:self.appId];
XCTAssertFalse([badClient testIntegrationWithMerchantId:nil]);
[OHHTTPStubs stubRequestsPassingTest:^BOOL(NSURLRequest * _Nonnull request) {
......@@ -1179,7 +1179,7 @@
} withStubResponse:^OHHTTPStubsResponse * _Nonnull(NSURLRequest * _Nonnull request) {
return [OHHTTPStubsResponse responseWithKey:@"testInvalidIntegrationBadShopUrl_0"];
}];
badClient = [[BUYClient alloc] initWithShopDomain:@"asdvfdbfdgasfgdsfg.myshopify.com" apiKey:self.apiKey channelId:self.channelId];
badClient = [[BUYClient alloc] initWithShopDomain:@"asdvfdbfdgasfgdsfg.myshopify.com" apiKey:self.apiKey appId:self.appId];
XCTAssertFalse([badClient testIntegrationWithMerchantId:nil]);
XCTAssertFalse([badClient testIntegrationWithMerchantId:@"blah"]);
......@@ -1326,8 +1326,8 @@
NSString *shopDomain = [self shouldUseMocks] ? BUYShopDomain_Placeholder : self.shopDomain;
NSString *apiKey = [self shouldUseMocks] ? BUYAPIKey_Placeholder : self.apiKey;
NSString *channelId = [self shouldUseMocks] ? BUYChannelId_Placeholder : self.channelId;
BUYClient *testClient = [[BUYClient alloc] initWithShopDomain:shopDomain apiKey:apiKey channelId:channelId];
NSString *appId = [self shouldUseMocks] ? BUYAppId_Placeholder : self.appId;
BUYClient *testClient = [[BUYClient alloc] initWithShopDomain:shopDomain apiKey:apiKey appId:appId];
testClient.queue = dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_HIGH, 0);
[testClient getShop:^(BUYShop *shop, NSError *error) {
......
......@@ -30,7 +30,7 @@
// These should be defined as environment variables in your scheme, or in the CI machine
#define kBUYTestDomain @"shop_domain"
#define kBUYTestAPIKey @"api_key"
#define kBUYTestChannelId @"channel_id"
#define kBUYTestAppId @"app_id"
#define kBUYTestMerchantId @"merchant_id"
#define kBUYTestGiftCardCode11 @"gift_card_code_11"
#define kBUYTestGiftCardCode25 @"gift_card_code_25"
......
This source diff could not be displayed because it is too large. You can view the blob instead.
......@@ -37,7 +37,7 @@
{
NSLog(@"Remove this call once integration succeeds. This should never be called in production code!!");
NSString *urlString = [NSString stringWithFormat:@"https://%@/mobile_app/verify?api_key=%@&channel_id=%@", self.shopDomain, self.apiKey, self.channelId];
NSString *urlString = [NSString stringWithFormat:@"https://%@/mobile_app/verify?api_key=%@&channel_id=%@", self.shopDomain, self.apiKey, self.appId];
if (merchantId.length > 0) {
urlString = [urlString stringByAppendingFormat:@"&merchant_id=%@", merchantId];
......
......@@ -225,11 +225,11 @@ typedef void (^BUYDataGiftCardBlock)(BUYGiftCard *giftCard, NSError *error);
*
* @param shopDomain The Shop Domain i.e. abetterlookingshop.myshopify.com
* @param apiKey The API key provided via the Mobile SDK Channel on Shopify Admin
* @param channelId The Channel ID provided on Shopify Admin
* @param appId The App ID provided on Shopify Admin
*
* @return An instance of BUYDataClient
*/
- (instancetype)initWithShopDomain:(NSString *)shopDomain apiKey:(NSString *)apiKey channelId:(NSString *)channelId NS_DESIGNATED_INITIALIZER;
- (instancetype)initWithShopDomain:(NSString *)shopDomain apiKey:(NSString *)apiKey appId:(NSString *)appId NS_DESIGNATED_INITIALIZER;
/**
* Queue where callbacks will be called
......@@ -255,7 +255,7 @@ typedef void (^BUYDataGiftCardBlock)(BUYGiftCard *giftCard, NSError *error);
/**
* The Channel ID set using the initializer
*/
@property (nonatomic, strong, readonly) NSString *channelId;
@property (nonatomic, strong, readonly) NSString *appId;
/**
* The Merchant ID is used for Apple Pay and set using `enableApplePayWithMerchantId:`
......
......@@ -56,14 +56,14 @@
NSString * const BUYVersionString = @"1.2.6";
static NSString *const kBUYClientPathProductPublications = @"product_publications";
static NSString *const kBUYClientPathCollectionPublications = @"collection_publications";
static NSString *const kBUYClientPathProductPublications = @"product_listings";
static NSString *const kBUYClientPathCollectionPublications = @"collection_listings";
@interface BUYClient () <NSURLSessionDelegate>
@property (nonatomic, strong) NSString *shopDomain;
@property (nonatomic, strong) NSString *apiKey;
@property (nonatomic, strong) NSString *channelId;
@property (nonatomic, strong) NSString *appId;
@property (nonatomic, strong) NSURLSession *session;
@property (nonatomic, strong) NSString *merchantId;
......@@ -74,7 +74,7 @@ static NSString *const kBUYClientPathCollectionPublications = @"collection_publi
- (instancetype)init { return nil; }
- (instancetype)initWithShopDomain:(NSString *)shopDomain apiKey:(NSString *)apiKey channelId:(NSString *)channelId
- (instancetype)initWithShopDomain:(NSString *)shopDomain apiKey:(NSString *)apiKey appId:(NSString *)appId
{
if (shopDomain.length == 0) {
NSException *exception = [NSException exceptionWithName:@"Bad shop domain" reason:@"Please ensure you initialize with a shop domain" userInfo:nil];
......@@ -85,7 +85,7 @@ static NSString *const kBUYClientPathCollectionPublications = @"collection_publi
if (self) {
self.shopDomain = shopDomain;
self.apiKey = apiKey;
self.channelId = channelId;
self.appId = appId;
self.applicationName = [[NSBundle mainBundle] infoDictionary][@"CFBundleName"] ?: @"";
self.queue = dispatch_get_main_queue();
self.session = [self createUrlSession];
......@@ -247,7 +247,7 @@ static NSString *const kBUYClientPathCollectionPublications = @"collection_publi
- (NSURLComponents *)URLComponentsForChannelsAppendingPath:(NSString *)appendingPath queryItems:(NSDictionary*)queryItems
{
return [self URLComponentsForAPIPath:[NSString stringWithFormat:@"channels/%@", self.channelId] appendingPath:appendingPath queryItems:queryItems];
return [self URLComponentsForAPIPath:[NSString stringWithFormat:@"apps/%@", self.appId] appendingPath:appendingPath queryItems:queryItems];
}
- (NSURLComponents *)URLComponentsForCheckoutsAppendingPath:(NSString *)appendingPath checkoutToken:(NSString *)checkoutToken queryItems:(NSDictionary*)queryItems
......@@ -298,10 +298,9 @@ static NSString *const kBUYClientPathCollectionPublications = @"collection_publi
- (void)configureCheckout:(BUYCheckout *)checkout
{
checkout.channelId = self.channelId;
checkout.marketingAttribution = @{@"medium": @"iOS", @"source": self.applicationName};
checkout.sourceName = @"mobile_app";
checkout.sourceIdentifier = checkout.channelId;
checkout.sourceIdentifier = self.appId;
if (self.urlScheme || checkout.webReturnToURL) {
checkout.webReturnToURL = checkout.webReturnToURL ?: self.urlScheme;
checkout.webReturnToLabel = checkout.webReturnToLabel ?: [@"Return to " stringByAppendingString:self.applicationName];
......
......@@ -167,11 +167,6 @@
@property (nonatomic, strong, readonly) NSArray<BUYGiftCard *> *giftCards;
/**
* Channel ID where the checkout was created
*/
@property (nonatomic, strong) NSString *channelId;
/**
* Attributions for the checkout, containing the application name and platform (defaults to applicationName set
* on the BUYClient, and "iOS" respectively
*/
......@@ -225,7 +220,7 @@
@property (nonatomic, copy, readonly) NSString *sourceName;
/**
* The unique identifier for the source: the channelId
* The unique identifier for the source: the appId
*/
@property (nonatomic, copy, readonly) NSString *sourceIdentifier;
......
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