-
Notifications
You must be signed in to change notification settings - Fork 6
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Codable protocol #23
base: master
Are you sure you want to change the base?
Codable protocol #23
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
import Foundation | ||
|
||
struct BoolResponse: Codable { | ||
let response: Bool | ||
} | ||
|
||
struct ResultResponse: Codable { | ||
let response: BoolResult | ||
} | ||
|
||
struct BoolResult: Codable { | ||
let result: Bool | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,24 +1,13 @@ | ||
import Foundation | ||
|
||
public class Token { | ||
public class TokenResponse: Codable { | ||
let response: Token | ||
} | ||
|
||
public struct Token: Codable { | ||
public let accessToken: String | ||
public let type: String | ||
public let expires: Date | ||
public let created: Date | ||
public let refreshToken: String | ||
|
||
init(dictionary: [String: AnyObject]) throws { | ||
guard let accessToken = dictionary["access_token"] as? String, | ||
let type = dictionary["token_type"] as? String, | ||
let expiresInteger = dictionary["expires_in"] as? Double, | ||
let createdInteger = dictionary["created_at"] as? Double, | ||
let refreshToken = dictionary["refresh_token"] as? String else { | ||
throw APIError() | ||
} | ||
self.accessToken = accessToken | ||
self.type = type | ||
self.expires = Date(timeIntervalSince1970: expiresInteger + createdInteger) | ||
self.created = Date(timeIntervalSince1970: createdInteger) | ||
self.refreshToken = refreshToken | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,21 @@ | ||
import Foundation | ||
|
||
public class Vehicle { | ||
public enum State: String { | ||
public class VehicleResponse: Codable { | ||
let response: [Vehicle] | ||
} | ||
|
||
public struct Vehicle: Codable { | ||
|
||
public enum State: String, Codable { | ||
case online | ||
} | ||
|
||
public let color: String? | ||
public let displayName: String? | ||
public let identifier: String | ||
public let optionCodes: [String] | ||
public let identifier: Int | ||
public let optionCodes: String | ||
public let vehicleIdentifier: Int | ||
public let vin: String | ||
public let tokens: [String] | ||
public let state: State | ||
|
||
init?(dictionary: [String: AnyObject]) { | ||
guard let identifierNumber = dictionary["id"] as? NSNumber, | ||
let optionCodes = dictionary["option_codes"] as? String, | ||
let vehicleIdentifier = dictionary["vehicle_id"] as? Int, | ||
let vin = dictionary["vin"] as? String, | ||
let tokens = dictionary["tokens"] as? [String], | ||
let stateString = dictionary["state"] as? String, | ||
let state = State(rawValue: stateString) else { | ||
return nil | ||
} | ||
self.color = dictionary["color"] as? String | ||
self.displayName = dictionary["display_name"] as? String | ||
self.identifier = identifierNumber.stringValue | ||
self.optionCodes = optionCodes.components(separatedBy: ",") | ||
self.vehicleIdentifier = vehicleIdentifier | ||
self.vin = vin | ||
self.tokens = tokens | ||
self.state = state | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
import Foundation | ||
|
||
public struct VehicleStateResponse: Codable { | ||
let response: VehicleState | ||
} | ||
|
||
public struct VehicleState: Codable { | ||
let parsedCalendarSupported: Double | ||
let spoilerType: String | ||
let rt: Double | ||
let carVersion: String | ||
let rearSeatType: Double | ||
let df: Double | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifier Name Violation: Variable name should be between 3 and 40 characters long: 'df' (identifier_name) |
||
let locked: Double | ||
let thirdRowSeats: String | ||
let sunRoofState: String | ||
let carType: String | ||
let remoteStartSupported: Double | ||
let hasSpoiler: Double | ||
let pf: Double | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifier Name Violation: Variable name should be between 3 and 40 characters long: 'pf' (identifier_name) |
||
let odometer: Double | ||
let lastAutoparkError: String | ||
let darkRims: Double | ||
let autoparkState: String | ||
let sunRoofInstalled: Double | ||
let sunRoofPercentOpen: Double | ||
let exteriorColor: String | ||
let timestamp: Double | ||
let vehicleName: String | ||
let homelinkNearby: Double | ||
let valetPinNeeded: Double | ||
let notificationsSupported: Double | ||
let pr: Double | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifier Name Violation: Variable name should be between 3 and 40 characters long: 'pr' (identifier_name) |
||
let rearSeatHeaters: Double | ||
let valetMode: Double | ||
let calendarSupported: Double | ||
let dr: Double | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifier Name Violation: Variable name should be between 3 and 40 characters long: 'dr' (identifier_name) |
||
let centerDisplayState: Double | ||
let apiVersion: Double | ||
let remoteStart: Double | ||
let ft: Double | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifier Name Violation: Variable name should be between 3 and 40 characters long: 'ft' (identifier_name) |
||
let autoparkStateV2: String | ||
let wheelType: String | ||
let perfConfig: String | ||
let autoparkStyle: String | ||
let roofColor: String | ||
let rhd: Double | ||
let seatType: Double | ||
|
||
private enum CodingKeys: String, CodingKey { | ||
case parsedCalendarSupported = "parsed_calendar_supported" | ||
case spoilerType = "spoiler_type" | ||
case rt | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifier Name Violation: Enum element name should be between 3 and 40 characters long: 'rt' (identifier_name) |
||
case carVersion = "car_version" | ||
case rearSeatType = "rear_seat_type" | ||
case df | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifier Name Violation: Enum element name should be between 3 and 40 characters long: 'df' (identifier_name) |
||
case locked | ||
case thirdRowSeats = "third_row_seats" | ||
case sunRoofState = "sun_roof_state" | ||
case carType = "car_type" | ||
case remoteStartSupported = "remote_start_supported" | ||
case hasSpoiler = "has_spoiler" | ||
case pf | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifier Name Violation: Enum element name should be between 3 and 40 characters long: 'pf' (identifier_name) |
||
case odometer | ||
case lastAutoparkError = "last_autopark_error" | ||
case darkRims = "dark_rims" | ||
case autoparkState = "autopark_state" | ||
case sunRoofInstalled = "sun_roof_installed" | ||
case sunRoofPercentOpen = "sun_roof_percent_open" | ||
case exteriorColor = "exterior_color" | ||
case timestamp | ||
case vehicleName = "vehicle_name" | ||
case homelinkNearby = "homelink_nearby" | ||
case valetPinNeeded = "valet_pin_needed" | ||
case notificationsSupported = "notifications_supported" | ||
case pr | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifier Name Violation: Enum element name should be between 3 and 40 characters long: 'pr' (identifier_name) |
||
case rearSeatHeaters = "rear_seat_heaters" | ||
case valetMode = "valet_mode" | ||
case calendarSupported = "calendar_supported" | ||
case dr | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifier Name Violation: Enum element name should be between 3 and 40 characters long: 'dr' (identifier_name) |
||
case centerDisplayState = "center_display_state" | ||
case apiVersion = "api_version" | ||
case remoteStart = "remote_start" | ||
case ft | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Identifier Name Violation: Enum element name should be between 3 and 40 characters long: 'ft' (identifier_name) |
||
case autoparkStateV2 = "autopark_state_v2" | ||
case wheelType = "wheel_type" | ||
case perfConfig = "perf_config" | ||
case autoparkStyle = "autopark_style" | ||
case roofColor = "roof_color" | ||
case rhd | ||
case seatType = "seat_type" | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Identifier Name Violation: Variable name should be between 3 and 40 characters long: 'rt' (identifier_name)