Last active
May 4, 2019 11:13
-
-
Save alexbaramilis/6d9b83c481e13b3015d47e51b77a4a32 to your computer and use it in GitHub Desktop.
AirVisual 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 AirVisualAPI { | |
static private let key = "A5xEAXuhEFJZyZA4o" | |
case nearestCity(lat: Double, lon: Double) | |
} | |
extension AirVisualAPI: TargetType { | |
var baseURL: URL { | |
return URL(string: "https://api.airvisual.com/v2")! | |
} | |
var path: String { | |
switch self { | |
case .nearestCity: return "/nearest_city" | |
} | |
} | |
var method: Moya.Method { | |
switch self { | |
case .nearestCity: return .get | |
} | |
} | |
var sampleData: Data { | |
return Data() | |
} | |
var task: Task { | |
switch self { | |
case let .nearestCity(lat, lon): | |
let parameters = [ | |
"lat": String(lat), | |
"lon": String(lon), | |
"key": AirVisualAPI.key | |
] | |
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