Skip to content

Commit

Permalink
Merge pull request #2 from godpp/develop
Browse files Browse the repository at this point in the history
Add : BoosterCenter request return type
  • Loading branch information
godpp authored Feb 21, 2019
2 parents 167b436 + 29415e4 commit 15b5ee1
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 16 deletions.
2 changes: 1 addition & 1 deletion Booster.podspec
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
24 changes: 9 additions & 15 deletions Sources/BoosterCenter.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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<Service: BoosterService> {

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)
}
Expand All @@ -41,19 +39,15 @@ public class BoosterCenter<Service: BoosterService> {
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
Expand Down
2 changes: 2 additions & 0 deletions Sources/BoosterService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 }
Expand Down

0 comments on commit 15b5ee1

Please sign in to comment.