/
Clients.swift
75 lines (64 loc) · 2.52 KB
/
Clients.swift
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import Shared
import SwiftyJSON
public struct RemoteClient: Equatable {
public let guid: GUID?
public let modified: Timestamp
public let name: String
public let type: String?
public let os: String?
public let version: String?
public let fxaDeviceId: String?
let protocols: [String]?
let appPackage: String?
let application: String?
let formfactor: String?
let device: String?
// Requires a valid ClientPayload (: CleartextPayloadJSON: JSON).
public init(json: JSON, modified: Timestamp) {
self.guid = json["id"].string
self.modified = modified
self.name = json["name"].stringValue
self.type = json["type"].string
self.version = json["version"].string
self.protocols = jsonsToStrings(json["protocols"].array)
self.os = json["os"].string
self.appPackage = json["appPackage"].string
self.application = json["application"].string
self.formfactor = json["formfactor"].string
self.device = json["device"].string
self.fxaDeviceId = json["fxaDeviceId"].string
}
public init(guid: GUID?, name: String, modified: Timestamp, type: String?, formfactor: String?, os: String?, version: String?, fxaDeviceId: String?) {
self.guid = guid
self.name = name
self.modified = modified
self.type = type
self.formfactor = formfactor
self.os = os
self.version = version
self.fxaDeviceId = fxaDeviceId
self.device = nil
self.appPackage = nil
self.application = nil
self.protocols = nil
}
}
// TODO: should this really compare tabs?
public func ==(lhs: RemoteClient, rhs: RemoteClient) -> Bool {
return lhs.guid == rhs.guid &&
lhs.name == rhs.name &&
lhs.modified == rhs.modified &&
lhs.type == rhs.type &&
lhs.formfactor == rhs.formfactor &&
lhs.os == rhs.os &&
lhs.version == rhs.version &&
lhs.fxaDeviceId == rhs.fxaDeviceId
}
extension RemoteClient: CustomStringConvertible {
public var description: String {
return "<RemoteClient GUID: \(guid ?? "nil"), name: \(name), modified: \(modified), type: \(type ?? "nil"), formfactor: \(formfactor ?? "nil"), OS: \(os ?? "nil"), version: \(version ?? "nil"), fxaDeviceId: \(fxaDeviceId ?? "nil")>"
}
}