ESAPIClient is an API client library built on top of AFNetworking.
- Minimum deployment target: iOS 9.0, macOS 10.10, watchOS 2.0, tvOS 9.0
pod 'ESAPIClient'
If you are using AFNetworking 3.x, you need to add my spec-repo source URL before the Trunk source in your Podfile
:
source 'https://github.com/ElfSundae/CocoaPods-Specs.git'
source 'https://cdn.cocoapods.org/'
target 'Example' do
pod 'ESAPIClient'
end
NSURL *baseURL = [NSURL URLWithString:@"https://api.github.com"];
ESAPIClient *client = [[ESAPIClient alloc] initWithBaseURL:baseURL];
client.fileMultipartName = @"uploadFile";
ESAPIClient.defaultClient = client;
[ESAPIClient.defaultClient GET:@"api/path" parameters:@{ @"foo": @"bar" } success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
//
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//
}];
[ESAPIClient.defaultClient uploadFile:fileURL
to:@"upload/avatar"
parameters:@{ @"foo": @"bar" }
progress:^(NSProgress * _Nonnull progress) {
dispatch_async(dispatch_get_main_queue(), ^{
progressView.progress = progress.fractionCompleted;
});
} success:^(NSURLSessionDataTask * _Nonnull task, id _Nullable responseObject) {
//
} failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
//
}];
[ESAPIClient.defaultClient download:@"download/file.zip" toFile:destFile parameters:nil progress:nil success:^(NSURLSessionDownloadTask * _Nonnull task, NSURL * _Nonnull filePath) {
//
} failure:^(NSURLSessionDownloadTask * _Nullable task, NSError * _Nonnull error) {
//
}];
[ESAPIClient.defaultClient download:@"https://example.com/file.zip" toDirectory:destDir parameters:nil progress:nil success:^(NSURLSessionDownloadTask * _Nonnull task, NSURL * _Nonnull filePath) {
//
} failure:^(NSURLSessionDownloadTask * _Nullable task, NSError * _Nonnull error) {
//
}];
ESAPIClient is available under the MIT license. See the LICENSE file for more info.