#BETURLSession
Using NSURLSession and the rest of the new iOS 7 & Mavericks foundation network classes, wrapped with syntactic sugar and convenience. No need to inherit and make a singleton. The category will keep track of your session with a session name.
##Overview
A incredibly light weight and source-readable HTTP client. Plugginable Serializers on top of builting foundation classes NSURLSession and NSURLSessionTask. Life-cycle callbacks (think before_filter or after_filter) Upload & Download progress blocks. Choose delegates and/or blocks Convenience serializers (JSON out of the box by default) to get started fast.
##Installation
pod 'BETURLSession'
##Setup
#import <BETURLSession.h>
NSURLSession * session = [NSURLSession bet_sessionWithName:@"Random" baseURLString:@"http://httpbin.org"];
NSMutableArray * bigData = @[].mutableCopy;
for (NSInteger i = 0; i!=50000; i++) [bigData addObject:@(i)];
NSURLSessionTask * task = [session bet_taskPOSTResource:@"post"
withParams:@{@"POST" : bigData}
completion:^(BETResponse *response) {
NSLog(@"POST completed with code %@ & error %@",
@(response.HTTPURLResponse.statusCode),
response.error
);
}];
BETURLSessionTaskProgressHandlerBlock (^progressHandlerWithName)(NSString *) = ^BETURLSessionTaskProgressHandlerBlock(NSString * name) {
return ^(NSURLSessionTask *task, NSInteger bytes, NSInteger totalBytes, NSInteger totalBytesExpected) {
NSLog(@"%@ : %@ <-> %@ <-> %@", name, @(bytes), @(totalBytes), @(totalBytesExpected));
};
};
[task bet_setUploadProgressHandler:progressHandlerWithName(@"Upload")];
[task bet_setDownloadProgressHandler:progressHandlerWithName(@"Download")];
[task resume];
- Proper naming
- completion: for callbacks that are complete (option)
- completionHandler: callbacks that are complete but need action (required)
- handler: callbacks that need action but are not necessarily completion (required)
If you end up using BETURLSession in a project, we'd love to hear about it.
email: info@screeninteraction.com
twitter: @ScreenTwitt
BETURLSession is © 2013 Screen Interaction and may be freely
distributed under the MIT license.
See the LICENSE.md
file.