icloud-promise [work in progress]
Session based iCloud Client using request-promise based on Picklepete Pyicloud The module is implemented in pure coffee-script and requires coffee-script/register as shown in the example. The code is used in my Pimatic Phone plugin.
Some remarks on iOS devices
-
Notification emails: A notification email from Apple is generated when the iCloud session is established.
-
Two factor authentication: If activated, a notification dialog pops up on your device requiring a confirmation for the session. Also a verification code is displayed. It seems that neither the confirmation nor the verification code is necessary to access the iCloud device information.
-
Update interval: Requesting location information from the iPhone triggers the device to push the data to the iCloud. A short period increases power consumption significantly and may drain your battery.
Installation
npm install icloud-promise
Example
require 'coffee-script/register'iCloud = require'icloud-promise'_ = require 'lodash' apple_id = processenvICLOUD_USERNAMEpassword = processenvICLOUD_PASSWORDdevice = processenvICLOUD_DEVICE client = apple_idpasswordclientloginthen if clientauthenticated clientrefreshClient then found = _findclientdevicesname: device if found consolelog" location:"foundlocation else consolelog"Device not found!" catch consolelog'Update device failed, 'errormessage catch consolelog'Login failed, ' + errormessage
API
The documentation is incomlete. If in doubt, look at the source code ;-)
new ICloudClient(apple_id, password) => ICloudClient
require 'coffee-script/register'iCloud = require'icloud-promise'client = apple_idpassword
ICloudClientLogin() => Promise
The returned promise (request response or error)
client.login()
.then( (response) ->
do something ...
).catch( (error) ->
handle errors ...
)
ICloudClient.authenticated => Boolean
Returns true after a successful login request
ICloudClient.refreshClient() => Promise
Updates the ICloudClient.devices list current information
client.refreshClient()
.then( () ->
do something with client.devices
).catch( (error) ->
handle errors ...
)
More API calls ...
... will be implemented in the near future.