Initial implementation of thetvdb json api.

This commit is contained in:
Damiano Galassi committed 2017-05-24 10:00:04 +02:00
1 parent 206ed00596
commit 964c171e1e
12 files changed
+384 -172

No files matched your search

+11 -3
View File
@@ -145,7 +145,7 @@
return [NSString stringWithString:r];
}
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url withCachePolicy:(SBCachePolicy)policy {
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url HTTPMethod:(NSString *)method HTTPBody:(nullable NSData *)body headerOptions:(nullable NSDictionary *)header cachePolicy:(SBCachePolicy)policy {
dispatch_semaphore_t sem = dispatch_semaphore_create(0);
__block NSData *downloadedData;
@@ -163,7 +163,7 @@
break;
}
[[self sessionTaskFromUrl:url HTTPMethod:@"GET" headerOptions:nil cachePolicy:cachePolicy completionHandler:^(NSData * _Nullable data) {
[[self sessionTaskFromUrl:url HTTPMethod:method HTTPBody:body headerOptions:header cachePolicy:cachePolicy completionHandler:^(NSData * _Nullable data) {
downloadedData = data;
dispatch_semaphore_signal(sem);
}] resume];
@@ -173,8 +173,12 @@
return downloadedData;
}
+ (nullable NSData *)downloadDataFromURL:(NSURL *)url cachePolicy:(SBCachePolicy)policy {
return [self downloadDataFromURL:url HTTPMethod:@"GET" HTTPBody:nil headerOptions:nil cachePolicy:policy];
}
#pragma mark NSURLRequest
+ (NSURLSessionTask *)sessionTaskFromUrl:(NSURL *)url HTTPMethod:(NSString *)method headerOptions:(nullable NSDictionary *)header cachePolicy:(NSURLRequestCachePolicy)cachePolicy completionHandler:(void(^)(NSData * _Nullable data))completionHandler
+ (NSURLSessionTask *)sessionTaskFromUrl:(NSURL *)url HTTPMethod:(NSString *)method HTTPBody:(nullable NSData *)body headerOptions:(nullable NSDictionary *)header cachePolicy:(NSURLRequestCachePolicy)cachePolicy completionHandler:(void(^)(NSData * _Nullable data))completionHandler
{
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url
cachePolicy:cachePolicy
@@ -187,6 +191,10 @@
}
}
if (body) {
request.HTTPBody = body;
}
NSURLSession *defaultSession = [NSURLSession sharedSession];
NSURLSessionTask *task = [defaultSession dataTaskWithRequest:request completionHandler:^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (data) {