Commit 1c040c62 by Brent Gulanowski Committed by GitHub

Merge pull request #276 from Shopify/task/collection-handle

Add support to get collection with handle
parents a353280d 405f96fd
......@@ -253,6 +253,26 @@
}];
}
- (void)testCollectionHandle
{
[OHHTTPStubs stubUsingResponseWithKey:@"testGetCollection_0" useMocks:[self shouldUseMocks]];
XCTestExpectation *expectation = [self expectationWithDescription:NSStringFromSelector(_cmd)];
[self.client getCollectionByHandle:@"frontpage" completion:^(BUYCollection * _Nullable collection, NSError * _Nullable error) {
XCTAssertNotNil(collection);
XCTAssertEqualObjects(@"Frontpage", collection.title);
XCTAssertEqualObjects(@109931075, collection.identifier);
XCTAssertNil(error);
[expectation fulfill];
}];
[self waitForExpectationsWithTimeout:10 handler:^(NSError *error) {
XCTAssertNil(error);
}];
}
- (void)testProductsInCollection
{
if (self.collection == nil) {
......
......@@ -78,6 +78,14 @@ typedef NS_ENUM(NSUInteger, BUYCollectionSort) {
typedef void (^BUYDataShopBlock)(BUYShop * _Nullable shop, NSError * _Nullable error);
/**
* Return block containing a BUYCollection object and/or an NSError
*
* @param collection A BUYCollection object.
* @param error Optional NSError
*/
typedef void (^BUYDataCollectionBlock)(BUYCollection* _Nullable collection, NSError * _Nullable error);
/**
* Return block containing a list of BUYCollection objects and/or an NSError
*
* @param collections An array of BUYCollection objects
......@@ -136,7 +144,7 @@ typedef void (^BUYDataTagsListBlock)(NSArray <NSString *> * _Nullable tags, NSUI
*
* @param block (^BUYDataShopBlock)(BUYShop *shop, NSError *error);
*
* @return The associated BUYRequestOperation
* @return The associated operation
*/
- (NSOperation *)getShop:(BUYDataShopBlock)block;
......@@ -146,7 +154,7 @@ typedef void (^BUYDataTagsListBlock)(NSArray <NSString *> * _Nullable tags, NSUI
* @param page Page to request. Pages start at 1.
* @param block (^BUYDataProductListBlock)(NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error);
*
* @return The associated BUYRequestOperation
* @return The associated operation
*/
- (NSOperation *)getProductsPage:(NSUInteger)page completion:(BUYDataProductListBlock)block;
......@@ -156,7 +164,7 @@ typedef void (^BUYDataTagsListBlock)(NSArray <NSString *> * _Nullable tags, NSUI
* @param handle Product handle
* @param block (^BUYDataProductBlock)(BUYProduct *product, NSError *error);
*
* @return The associated BUYRequestOperation
* @return The associated operation
*/
- (NSOperation *)getProductByHandle:(NSString *)handle completion:(BUYDataProductBlock)block;
......@@ -166,7 +174,7 @@ typedef void (^BUYDataTagsListBlock)(NSArray <NSString *> * _Nullable tags, NSUI
* @param productId Product ID
* @param block (^BUYDataProductBlock)(BUYProduct *product, NSError *error);
*
* @return The associated BUYRequestOperation
* @return The associated operation
*/
- (NSOperation *)getProductById:(NSNumber *)productId completion:(BUYDataProductBlock)block;
......@@ -176,7 +184,7 @@ typedef void (^BUYDataTagsListBlock)(NSArray <NSString *> * _Nullable tags, NSUI
* @param productIds An array of `NSString` objects with Product IDs to fetch
* @param block (^BUYDataProductsBlock)(NSArray *products, NSError *error);
*
* @return The associated BUYRequestOperation
* @return The associated operation
*/
- (NSOperation *)getProductsByIds:(NSArray<NSNumber *> *)productIds completion:(BUYDataProductsBlock)block;
......@@ -191,12 +199,22 @@ typedef void (^BUYDataTagsListBlock)(NSArray <NSString *> * _Nullable tags, NSUI
- (NSOperation *)getProductTagsPage:(NSUInteger)page completion:(BUYDataTagsListBlock)block;
/**
* Fetch a single collection by the handle of the collection.
*
* @param handle Collection handle
* @param block (^BUYDataCollectionBlock)(BUYCollection* _Nullable collection, NSError * _Nullable error)
*
* @return The associated operation.
*/
- (NSOperation *)getCollectionByHandle:(NSString *)handle completion:(BUYDataCollectionBlock)block;
/**
* Fetches collections based off page
*
* @param page Index of the page requested
* @param block (^BUYDataCollectionsBlock)(NSArray *collections, NSError *error)
*
* @return The associated BUYRequestOperation
* @return The associated operation
*/
- (NSOperation *)getCollectionsPage:(NSUInteger)page completion:(BUYDataCollectionsListBlock)block;
......@@ -208,7 +226,7 @@ typedef void (^BUYDataTagsListBlock)(NSArray <NSString *> * _Nullable tags, NSUI
* @param collectionId The `collectionId` found in the BUYCollection object to fetch the products from
* @param block (NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error)
*
* @return the associated BUYRequestOperation
* @return the associated operation
*/
- (NSOperation *)getProductsPage:(NSUInteger)page inCollection:(NSNumber *)collectionId completion:(BUYDataProductListBlock)block;
......@@ -221,7 +239,7 @@ typedef void (^BUYDataTagsListBlock)(NSArray <NSString *> * _Nullable tags, NSUI
* @param sortOrder The sort order that overrides the default collection sort order
* @param block (NSArray *products, NSUInteger page, BOOL reachedEnd, NSError *error)
*
* @return the associated BUYRequestOperation
* @return the associated operation
*/
- (NSOperation *)getProductsPage:(NSUInteger)page inCollection:(nullable NSNumber *)collectionId withTags:(nullable NSArray <NSString *> *)tags sortOrder:(BUYCollectionSort)sortOrder completion:(BUYDataProductListBlock)block;
......
......@@ -141,6 +141,21 @@ static NSString * const BUYCollectionsKey = @"collection_listings";
}];
}
- (NSOperation *)getCollectionByHandle:(NSString *)handle completion:(BUYDataCollectionBlock)block
{
NSURL *url = [self urlForCollectionListingsWithParameters:@{
@"handle" : handle
}];
return [self getRequestForURL:url completionHandler:^(NSDictionary *json, NSHTTPURLResponse *response, NSError *error) {
BUYCollection *collection = nil;
if (json && !error) {
collection = [self.modelManager buy_objectWithEntityName:[BUYCollection entityName] JSONDictionary:json[BUYCollectionsKey][0]];
}
block(collection, error);
}];
}
- (NSOperation *)getCollectionsPage:(NSUInteger)page completion:(BUYDataCollectionsListBlock)block
{
NSURL *url = [self urlForCollectionListingsWithParameters:@{
......
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