Skip to content

Commit

Permalink
Build a remove device API endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
robbiet480 committed Oct 5, 2016
1 parent 208a42f commit 3abf0bc
Showing 1 changed file with 39 additions and 0 deletions.
39 changes: 39 additions & 0 deletions HomeAssistant/HAAPI.swift
Original file line number Diff line number Diff line change
Expand Up @@ -586,6 +586,29 @@ public class HomeAssistantAPI {
return Mapper().toJSON(ident)
}

func buildRemovalDict() -> [String:Any] {
let deviceKitDevice = Device()

let ident = IdentifyRequest()
ident.AppBuildNumber = Int(string: Bundle.main.object(forInfoDictionaryKey: "CFBundleVersion")! as! String)
ident.AppBundleIdentifer = Bundle.main.bundleIdentifier
ident.AppVersionNumber = Double(Bundle.main.object(forInfoDictionaryKey: "CFBundleShortVersionString") as! String)
ident.DeviceID = deviceID
ident.DeviceLocalizedModel = deviceKitDevice.localizedModel
ident.DeviceModel = deviceKitDevice.model
ident.DeviceName = deviceKitDevice.name
ident.DevicePermanentID = DeviceUID.uid()
ident.DeviceSystemName = deviceKitDevice.systemName
ident.DeviceSystemVersion = deviceKitDevice.systemVersion
ident.DeviceType = deviceKitDevice.description
ident.Permissions = self.enabledPermissions
ident.PushID = endpointARN.components(separatedBy: "/").last!
ident.PushSounds = listAllInstalledPushNotificationSounds()
ident.PushToken = deviceToken

return Mapper().toJSON(ident)
}

func identifyDevice() -> Promise<String> {
let queryUrl = baseAPIURL+"ios/identify"
return Promise { fulfill, reject in
Expand All @@ -602,6 +625,22 @@ public class HomeAssistantAPI {
}
}

func removeDevice() -> Promise<String> {
let queryUrl = baseAPIURL+"ios/identify"
return Promise { fulfill, reject in
let _ = self.manager!.request(queryUrl, method: .delete, parameters: buildRemovalDict(), encoding: JSONEncoding.default).validate().responseString { response in
switch response.result {
case .success:
fulfill(response.result.value!)
case .failure(let error):
CLSLogv("Error when attemping to identifyDevice(): %@", getVaList([error.localizedDescription]))
Crashlytics.sharedInstance().recordError(error)
reject(error)
}
}
}
}

func setupPushActions() -> Promise<Set<UIUserNotificationCategory>> {
let queryUrl = baseAPIURL+"ios/push"
return Promise { fulfill, reject in
Expand Down

0 comments on commit 3abf0bc

Please sign in to comment.