TestsTested | ✗ |
LangLanguage | Obj-CObjective C |
License | Custom |
ReleasedLast Release | Oct 2015 |
Maintained by Dustin Bachrach.
Depends on: | |
Avenue | ~> 0.4 |
JSONModel | ~> 1.1 |
PromiseKit/CorePromise | ~> 3.0 |
AvenueFetcher is a simple component that builds on Avenue. It provides an abstract class, AVEFetcher
that makes fetching JSONModel model objects from network requests easy.
Simply Subclass AVEFetcher, and impelment +sharedFetcher
:
@interface MYFetcher : AVEFetcher
@end
@implementation MYFetcher
+ (instancetype)sharedFetcher
{
static id sharedInstance = nil;
static dispatch_once_t onceToken;
dispatch_once(&onceToken, ^{
sharedInstance = [[self alloc] init];
});
return sharedInstance;
}
You also need to configure the fetcher's builder
. A builder is an instance of AVEHTTPRequestOperationBuilder
. It describes details about all of the fetcher's requests, like baseURL, request/response serialization, security policy, etc.
Typically, you will want to configure the builder
in your -init
method:
- (instancetype)init
{
if (self = [super init]) {
NSURL* baseURL = [NSURL URLWithString:@"https://myurl.com"];
AVEHTTPRequestOperationBuilder* builder = [[AVEHTTPRequestOperationBuilder alloc] initWithBaseURL:baseURL];
self.builder = builder;
}
return self;
}
Making requests with the fetcher is simple:
[[MYFetcher sharedFetcher] fetchModel:MYModel.class
path:@"model/1"
keyPath:nil
parameters:nil
priority:[AVENetworkPriority priorityWithLevel:AVENetworkPriorityLevelHigh]
networkToken:nil].then(^(MYModel* model) {
// Use the `model`.
});
You can also make POST
and PUT
requests and treat the returned response as a model.
[[MYFetcher sharedFetcher] postAndFetchModel:MYModel.class
path:@"model/1"
keyPath:nil
parameters:parameters].then(^(MYModel* model) {
// Use the `model`.
});
[[MYFetcher sharedFetcher] putAndFetchModel:MYModel.class
path:@"model/1"
keyPath:nil
parameters:parameters].then(^(MYModel* model) {
// Use the `model`.
});
MediaHound
Avenue is available under the Apache License 2.0. See the LICENSE file for more info.