-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathClimateStateRequest.swift
More file actions
35 lines (32 loc) · 1.18 KB
/
ClimateStateRequest.swift
File metadata and controls
35 lines (32 loc) · 1.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
import Foundation
public struct ClimateStateRequest: RequestProtocol {
typealias CompletionType = ClimateState
var path: String {
return "/api/1/vehicles/\(vehicleIdentifier)/data_request/climate_state"
}
let method = WebRequest.RequestMethod.get
let accessToken: String
let vehicleIdentifier: String
public init(accessToken: String, vehicleIdentifier: String) {
self.accessToken = accessToken
self.vehicleIdentifier = vehicleIdentifier
}
public func execute(completion: @escaping (Result<ClimateState>) -> Void) {
WebRequest.request(
path: path,
method: method,
accessToken: accessToken) { response, error in
if let error = error {
DispatchQueue.main.async {
completion(Result.failure(error))
}
return
}
let responseDict = response as! [String: [String: Any]]
let dataDict = responseDict["response"]!
DispatchQueue.main.async {
completion(Result.success(ClimateState(dict: dataDict)))
}
}
}
}