diff --git a/Booster.podspec b/Booster.podspec index 71c33b2..bbd350f 100644 --- a/Booster.podspec +++ b/Booster.podspec @@ -16,7 +16,7 @@ Pod::Spec.new do |s| # s.name = "Booster" - s.version = "0.0.2" + s.version = "0.0.3" s.summary = "Booster is an HTTP networking librart written in Swift." # This description is used to generate tags and improve search results. diff --git a/Sources/BoosterCenter.swift b/Sources/BoosterCenter.swift index 5d2946f..3559a36 100644 --- a/Sources/BoosterCenter.swift +++ b/Sources/BoosterCenter.swift @@ -8,21 +8,19 @@ import Foundation -public typealias HTTPHeader = [HTTPHeaderField: String] +public typealias DataCompletion = (_ data: Data?, _ error: BoosterError?) -> Void + +public typealias JSONCompletion = (_ rawJSON: String?, _ error: BoosterError?) -> Void public class BoosterCenter { public init() {} - public func request( - _ service: Service, - completion: @escaping ( - _ data: Data?, - _ error: BoosterError? - ) -> Void) { + public func request(_ service: Service, completion: @escaping DataCompletion) -> URLSessionDataTask { + var dataTask = URLSessionDataTask() do { let urlRequest = try makeURLRequest(from: service) - let task = URLSession.shared.dataTask(with: urlRequest) { (data, response, _) in + dataTask = URLSession.shared.dataTask(with: urlRequest) { (data, response, _) in guard let data = data else { return completion(nil, BoosterError.noData) } @@ -41,19 +39,15 @@ public class BoosterCenter { completion(data, BoosterError.serverError(statusCode: statusCode)) } } - task.resume() + dataTask.resume() } catch { completion(nil, BoosterError.makeURLRequestFail) } + return dataTask } /// requestDownload is download task to json file. - public func requestDownload( - _ service: Service, - completion: @escaping ( - _ rawJSON: String?, - _ error: BoosterError? - ) -> Void) { + public func requestDownload(_ service: Service, completion: @escaping JSONCompletion) { do { let urlRequest = try makeURLRequest(from: service) let task = URLSession.shared.downloadTask(with: urlRequest) { (localURL, response, _) in diff --git a/Sources/BoosterService.swift b/Sources/BoosterService.swift index 6bfa87d..676bc6d 100644 --- a/Sources/BoosterService.swift +++ b/Sources/BoosterService.swift @@ -10,6 +10,8 @@ import Foundation //MARK: - Base Protocol Service +public typealias HTTPHeader = [HTTPHeaderField: String] + /// This Protocol is basic implementation for EndPoint public protocol BoosterService { var baseURL: URL { get }