-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathMobileEnabledForVehicleRequest.swift
More file actions
34 lines (31 loc) · 1.14 KB
/
MobileEnabledForVehicleRequest.swift
File metadata and controls
34 lines (31 loc) · 1.14 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
import Foundation
struct MobileEnabledForVehicleRequest: RequestProtocol {
typealias CompletionType = Bool
var path: String {
return "/api/1/vehicles/\(vehicleIdentifier)/mobile_enabled"
}
let vehicleIdentifier: String
let method = WebRequest.RequestMethod.get
let accessToken: String
init(vehicle: Vehicle, accessToken: String) {
self.vehicleIdentifier = vehicle.identifier
self.accessToken = accessToken
}
func execute(completion: @escaping (Result<Bool>) -> Void) {
WebRequest.request(
path: path,
method: method,
accessToken: accessToken) { response, error in
DispatchQueue.main.async {
if let error = error {
completion(Result.failure(error))
} else if let response = response as? [String: Bool],
let responseBool = response["response"] {
completion(Result.success(responseBool))
} else {
completion(Result.failure(APIError()))
}
}
}
}
}