Commit bffe25f3 by Brent Gulanowski

Add method to get collection by handle.

parent a353280d
...@@ -78,6 +78,14 @@ typedef NS_ENUM(NSUInteger, BUYCollectionSort) { ...@@ -78,6 +78,14 @@ typedef NS_ENUM(NSUInteger, BUYCollectionSort) {
typedef void (^BUYDataShopBlock)(BUYShop * _Nullable shop, NSError * _Nullable error); 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 * Return block containing a list of BUYCollection objects and/or an NSError
* *
* @param collections An array of BUYCollection objects * @param collections An array of BUYCollection objects
...@@ -191,6 +199,16 @@ typedef void (^BUYDataTagsListBlock)(NSArray <NSString *> * _Nullable tags, NSUI ...@@ -191,6 +199,16 @@ typedef void (^BUYDataTagsListBlock)(NSArray <NSString *> * _Nullable tags, NSUI
- (NSOperation *)getProductTagsPage:(NSUInteger)page completion:(BUYDataTagsListBlock)block; - (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 * Fetches collections based off page
* *
* @param page Index of the page requested * @param page Index of the page requested
......
...@@ -141,6 +141,21 @@ static NSString * const BUYCollectionsKey = @"collection_listings"; ...@@ -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];
}
block(collection, error);
}];
}
- (NSOperation *)getCollectionsPage:(NSUInteger)page completion:(BUYDataCollectionsListBlock)block - (NSOperation *)getCollectionsPage:(NSUInteger)page completion:(BUYDataCollectionsListBlock)block
{ {
NSURL *url = [self urlForCollectionListingsWithParameters:@{ 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