diff --git a/README.md b/README.md index 0d8bc86..19da605 100644 --- a/README.md +++ b/README.md @@ -28,7 +28,7 @@ Here's a basic example using all the methods var icloud = require("find-my-iphone").findmyphone; icloud.apple_id = "steve@jobs.com"; - icloud.password = "oneMoreThing"; + icloud.password = "oneMoreThing"; icloud.getDevices(function(error, devices) { var device; @@ -54,7 +54,7 @@ Here's a basic example using all the methods console.log("Driving time: " + result.duration.text); }); - icloud.alertDevice(device.id, function(err) { + icloud.alertDevice({deviceID: device.id, subject: 'node.js demo'}, function(err) { console.log("Beep Beep!"); }); @@ -91,11 +91,7 @@ find(email,password[,label[,callback]]) * password (required): Your iCloud password * label (optional): The label of the phone you want to alert (iCloud accounts may have multiple devices). The label can be found under "All Devices" in the Find My iPhone app. If there are multiple phones with the same label, the last one matching will be alerted. You should rename devices to be unique. * callback (optional): A function to execute when the phone has been alerted - + # Tests `apple_id=someone@gmail.com apple_password=somePassword mocha test` - - - - diff --git a/index.js b/index.js index d245adf..e096c54 100644 --- a/index.js +++ b/index.js @@ -139,14 +139,26 @@ var findmyphone = { callback(error, devices); }); }, - alertDevice: function(deviceId, callback) { - var options = { - url: findmyphone.base_path + "/fmipservice/client/web/playSound", - json: { - "subject": "Amazon Echo Find My iPhone Alert", - "device": deviceId + alertDevice: function(options, callback) { + var url = findmyphone.base_path + "/fmipservice/client/web/playSound"; + if ('object' === typeof(options) && options.hasOwnProperty('deviceID')) { + options = { + url: url, + json: { + "subject": options.subject || "Amazon Echo Find My iPhone Alert", + "device": options.deviceID + } } - }; + } + else { // backwards compatibility for deviceId string provided + options = { + url: url, + json: { + "subject": "Amazon Echo Find My iPhone Alert", + "device": options + } + }; + } findmyphone.iRequest.post(options, callback); }, getLocationOfDevice: function(device, callback) {