From 82b069b4604b1054bfd1c913397265b0afd2f48c Mon Sep 17 00:00:00 2001 From: Patrick Butkiewicz Date: Sun, 27 Nov 2016 01:56:44 -0500 Subject: [PATCH 1/2] First pass at linux support --- Sources/APIClient.swift | 16 ++++++++-------- Sources/CoberturaCoverage.swift | 2 +- Sources/Job.swift | 2 +- Sources/JobConfiguration.swift | 2 +- Sources/JobParameter.swift | 2 +- 5 files changed, 12 insertions(+), 12 deletions(-) diff --git a/Sources/APIClient.swift b/Sources/APIClient.swift index 1dc74c4..2496ecd 100644 --- a/Sources/APIClient.swift +++ b/Sources/APIClient.swift @@ -66,7 +66,7 @@ internal final class APIClient: NSObject { self.baseURL = url } - func get(path: URL, rawResponse: Bool = false, headers: [String : String] = [:], params: [String : AnyObject] = [:], _ handler: @escaping (AnyObject?, Error?) -> Void) { + func get(path: URL, rawResponse: Bool = false, headers: [String : String] = [:], params: [String : String] = [:], _ handler: @escaping (AnyObject?, Error?) -> Void) { let request: URLRequest = requestFor(path, method: .GET, headers: headers, params: params, body: nil) let session = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: nil) let task = session.dataTask(with: request) { data, response, error in @@ -76,7 +76,7 @@ internal final class APIClient: NSObject { task.resume() } - func post(path: URL, rawResponse: Bool = false, headers: [String : String] = [:], params: [String : AnyObject] = [:], body: String? = nil, _ handler: @escaping (AnyObject?, Error?) -> Void) { + func post(path: URL, rawResponse: Bool = false, headers: [String : String] = [:], params: [String : String] = [:], body: String? = nil, _ handler: @escaping (AnyObject?, Error?) -> Void) { let bodyData: Data? = body?.data(using: String.Encoding.utf8) let request: URLRequest = requestFor(path, method: .POST, headers: headers, params: params, body: bodyData) let session = URLSession(configuration: URLSessionConfiguration.default, delegate: self, delegateQueue: nil) @@ -90,7 +90,7 @@ internal final class APIClient: NSObject { // MARK: Private Helpers - private func requestFor(_ url: URL, method: APIMethod, headers: [String : String] = [:], params: [String : AnyObject] = [:], body: Data?) -> URLRequest { + private func requestFor(_ url: URL, method: APIMethod, headers: [String : String] = [:], params: [String : String] = [:], body: Data?) -> URLRequest { var request = URLRequest(url: url, cachePolicy: .reloadIgnoringLocalCacheData, timeoutInterval: ApiClientTimeout) request.httpMethod = method.description request.addValue(encodedAuthorizationHeader, forHTTPHeaderField: "Authorization") @@ -106,11 +106,11 @@ internal final class APIClient: NSObject { } else { var components = URLComponents(url: url, resolvingAgainstBaseURL: false) let queryItems: [URLQueryItem] = params.map { - if let val = $0.value as? String { - return URLQueryItem(name: $0.key, value: val) - } else { - return URLQueryItem(name: $0.key, value: String(describing: $0.value)) - } +// if let val = $0.value as? String { + return URLQueryItem(name: $0.key, value: $0.value) +// } else { +// return URLQueryItem(name: $0.key, value: String(describing: $0.value)) +// } } components?.queryItems = queryItems diff --git a/Sources/CoberturaCoverage.swift b/Sources/CoberturaCoverage.swift index f2414c4..5565ac6 100644 --- a/Sources/CoberturaCoverage.swift +++ b/Sources/CoberturaCoverage.swift @@ -95,7 +95,7 @@ extension Jenkins { return handler(nil) } - let parameters: [String : AnyObject] = ["depth" : depth as AnyObject] + let parameters: [String : String] = ["depth" : String(depth)] client?.get(path: url, params: parameters) { response, error in guard let json = response as? JSON, let results = json["results"] as? JSON else { diff --git a/Sources/Job.swift b/Sources/Job.swift index 7c4d65c..4bb7810 100644 --- a/Sources/Job.swift +++ b/Sources/Job.swift @@ -233,7 +233,7 @@ public extension Jenkins { return } - client?.post(path: url, params: parameters as [String : AnyObject]) { response, error in + client?.post(path: url, params: parameters) { response, error in handler(error) } } diff --git a/Sources/JobConfiguration.swift b/Sources/JobConfiguration.swift index cd77905..86ea930 100644 --- a/Sources/JobConfiguration.swift +++ b/Sources/JobConfiguration.swift @@ -111,7 +111,7 @@ public extension Jenkins { return } - client?.post(path: url, params: ["description" : description as AnyObject]) { response, error in + client?.post(path: url, params: ["description" : description]) { response, error in handler(error) } } diff --git a/Sources/JobParameter.swift b/Sources/JobParameter.swift index 888ac1d..8d81d65 100644 --- a/Sources/JobParameter.swift +++ b/Sources/JobParameter.swift @@ -29,7 +29,7 @@ public struct JobParameter { } if let defaultValueBlock = json["defaultParameterValue"] as? JSON, - let defaultValue = defaultValueBlock["value"] as AnyObject! { + let defaultValue = defaultValueBlock["value"] { self.parameter = defaultValue } } From 22f676e282e483706ae643056ee3153612914408 Mon Sep 17 00:00:00 2001 From: Patrick Butkiewicz Date: Sun, 27 Nov 2016 02:10:37 -0500 Subject: [PATCH 2/2] Add travis scripts --- .travis.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.travis.yml b/.travis.yml index a88f9cc..e806e0f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,4 +1,10 @@ os: + - linux - osx language: generic +sudo: required +dist: trusty osx_image: xcode8 +script: + - eval "$(curl -sL https://swift.vapor.sh/ci)" + - eval "$(curl -sL https://swift.vapor.sh/codecov)"