Created
May 4, 2019 11:17
-
-
Save alexbaramilis/ab0637ce1b7465c5c2e4101e5f6fa5d7 to your computer and use it in GitHub Desktop.
Air by Propeller API with Moya.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Foundation | |
import Moya | |
enum PropellerAPI { | |
case forecast(lat: Double, lon: Double) | |
} | |
extension PropellerAPI: TargetType { | |
var baseURL: URL { | |
return URL(string: "https://open.propellerhealth.com/prod")! | |
} | |
var path: String { | |
switch self { | |
case .forecast: return "/forecast" | |
} | |
} | |
var method: Moya.Method { | |
switch self { | |
case .forecast: return .get | |
} | |
} | |
var sampleData: Data { | |
return Data() | |
} | |
var task: Task { | |
switch self { | |
case let .forecast(lat, lon): | |
let parameters = [ | |
"latitude": String(lat), | |
"longitude": String(lon) | |
] | |
return .requestParameters(parameters: parameters, | |
encoding: URLEncoding.default) | |
} | |
} | |
var headers: [String : String]? { | |
return nil | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment