diff --git a/.editorconfig b/.editorconfig
new file mode 100644
index 0000000..7187366
--- /dev/null
+++ b/.editorconfig
@@ -0,0 +1,13 @@
+root = true
+
+[*]
+indent_style = space
+indent_size = 2
+
+[*.php]
+charset = utf-8
+end_of_line = lf
+indent_style = tab
+indent_size = 1
+insert_final_newline = true
+trim_trailing_whitespace = true
diff --git a/.gitignore b/.gitignore
new file mode 100644
index 0000000..850dc9a
--- /dev/null
+++ b/.gitignore
@@ -0,0 +1,35 @@
+# autotune
+autotune.jso
+
+# Managed by package managers
+/vendor/
+
+# Composer
+/composer.phar
+composer.lock
+
+# Mac
+.DS_Store
+
+# Project
+*.sublime-*
+### JetBrains template
+# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio
+
+*.iml
+
+## Directory-based project format:
+.idea/
+com_crashlytics_export_strings.xml
+crashlytics.properties
+crashlytics-build.properties
+
+test/nginx/*.conf
+!test/nginx/.gitkeep
+
+/.settings
+.buildpath
+.project
+.tags
+.tags1
+npm-debug.log
diff --git a/README.md b/README.md
index 69fc54f..abfe659 100644
--- a/README.md
+++ b/README.md
@@ -1,7 +1,7 @@
PHP-FindMyiPhone
================
-PHP class to locate, play sounds, and lock iOS devices
+PHP package to locate, play sounds, and lock iOS devices
What is the purpose?
@@ -35,8 +35,8 @@ Whats the simplest piece of code to get up and running
```php
printDevices();
?>
```
diff --git a/composer.json b/composer.json
new file mode 100644
index 0000000..b0ec041
--- /dev/null
+++ b/composer.json
@@ -0,0 +1,28 @@
+{
+ "name": "albeebe/findmyiphone",
+ "description": "Find My iPhone client library for PHP",
+ "homepage": "http://www.github.com/albeebe/PHP-FindMyiPhone",
+ "keywords": ["php", "iphone", "ios", "icloud", "findmyiphone"],
+ "type": "library",
+ "authors": [
+ {
+ "name": "Al Beebe",
+ "email": "alan.beebe@gmail.com",
+ "role": "Development"
+ },
+ {
+ "name": "Joost Faassen",
+ "email": "j.faassen@linkorb.com",
+ "role": "Packaging for Composer"
+ }
+ ],
+ "require": {
+ "php": ">=5.3.0"
+ },
+ "autoload": {
+ "psr-4": {
+ "FindMyiPhone\\": "src/"
+ }
+ },
+ "license": "Apache-2.0"
+}
diff --git a/example.php b/example.php
deleted file mode 100644
index 8f38cfa..0000000
--- a/example.php
+++ /dev/null
@@ -1,40 +0,0 @@
-getMessage();
- exit;
- }
-
- // This will print out all the devices on your account so you can grab the device IDs
- $fmi->printDevices();
-
- // Find a device that is reporting its location and attempt to get its current location
- foreach ($fmi->devices as $device) {
- if ($device->location->timestamp != "") {
- // Locate the device
- $location = $fmi->locate($device->ID);
-
- print "Device ".$device->ID." is located at ".$location->latitude.", ".$location->longitude."";
-
- // Play a sound on the device
- $fmi->playSound($device->ID, "You've been located!");
-
- // Lock the device
- //$fmi->lostMode($device->ID, "You got locked out", "555-555-5555");
-
- break;
- }
- }
-?>
diff --git a/examples/example.php b/examples/example.php
new file mode 100755
index 0000000..7d8fe37
--- /dev/null
+++ b/examples/example.php
@@ -0,0 +1,42 @@
+getMessage();
+ exit;
+}
+
+// This will print out all the devices on your account so you can grab the device IDs
+$fmi->printDevices();
+
+// Find a device that is reporting its location and attempt to get its current location
+foreach ($fmi->devices as $device) {
+ if ($device->location->timestamp != "") {
+ // Locate the device
+ $location = $fmi->locate($device->ID);
+
+ print "Device ".$device->ID." is located at ".$location->latitude.", ".$location->longitude."";
+
+ // Play a sound on the device
+ $fmi->playSound($device->ID, "You've been located!");
+
+ // Lock the device
+ //$fmi->lostMode($device->ID, "You got locked out", "555-555-5555");
+
+ break;
+ }
+}
+?>
diff --git a/class.findmyiphone.php b/src/Client.php
similarity index 93%
rename from class.findmyiphone.php
rename to src/Client.php
index 8b12fc2..f90b1b8 100644
--- a/class.findmyiphone.php
+++ b/src/Client.php
@@ -1,4 +1,4 @@
- "4.0",
@@ -180,7 +184,7 @@ private function authenticate() {
* This is where all the devices are downloaded and processed
* Example: print_r($fmi->devices)
*/
- private function getDevices() {
+ public function getDevices() {
$url = "https://fmipmobile.icloud.com/fmipservice/device/".$this->username."/initClient";
list($headers, $body) = $this->curlPOST($url, "", $this->username.":".$this->password);
$this->devices = array();
@@ -194,14 +198,14 @@ private function getDevices() {
* This method takes the raw device details from the API and converts it to a FindMyiPhoneDevice object
*/
private function generateDevice($deviceDetails) {
- $device = new FindMyiPhoneDevice();
+ $device = new Device();
$device->API = $deviceDetails;
$device->ID = $device->API["id"];
$device->batteryLevel = $device->API["batteryLevel"];
$device->batteryStatus = $device->API["batteryStatus"];
$device->class = $device->API["deviceClass"];
$device->displayName = $device->API["deviceDisplayName"];
- $device->location = new FindMyiPhoneLocation();
+ $device->location = new Location();
$device->location->timestamp = $device->API["location"]["timeStamp"];
$device->location->horizontalAccuracy = $device->API["location"]["horizontalAccuracy"];
$device->location->positionType = $device->API["location"]["positionType"];
@@ -237,14 +241,16 @@ private function curlPOST($url, $body, $authentication = "") {
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($ch, CURLOPT_VERBOSE, 1);
+ if ($this->debug) {
+ curl_setopt($ch, CURLOPT_VERBOSE, 1);
+ }
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_USERAGENT, $this->client["user-agent"]);
if (strlen($authentication) > 0) {
curl_setopt($ch, CURLOPT_USERPWD, $authentication);
}
$arrHeaders = array();
- $arrHeaders["Content-Length"] = strlen($request);
+ //$arrHeaders["Content-Length"] = strlen($request);
foreach ($this->client["headers"] as $key=>$value) {
array_push($arrHeaders, $key.": ".$value);
}
@@ -258,9 +264,12 @@ private function curlPOST($url, $body, $authentication = "") {
if ($i === 0)
$headers['http_code'] = $info["http_code"];
else {
- list ($key, $value) = explode(': ', $line);
- if (strlen($key) > 0)
- $headers[$key] = $value;
+ $part = explode(': ', $line);
+ if (count($part)>1) {
+ list ($key, $value) = explode(': ', $line);
+ if (strlen($key) > 0)
+ $headers[$key] = $value;
+ }
}
}
if ($this->debug) {
@@ -294,26 +303,3 @@ private function curlPOST($url, $body, $authentication = "") {
return array($headers, json_decode($responseBody, true));
}
}
-
-
-class FindMyiPhoneDevice {
- public $ID;
- public $batteryLevel;
- public $batteryStatus;
- public $class;
- public $displayName;
- public $location;
- public $model;
- public $modelDisplayName;
- public $name;
- public $API;
-}
-
-
-class FindMyiPhoneLocation {
- public $timestamp;
- public $horizontalAccuracy;
- public $positionType;
- public $longitude;
- public $latitude;
-}
diff --git a/src/Device.php b/src/Device.php
new file mode 100644
index 0000000..eaf09e0
--- /dev/null
+++ b/src/Device.php
@@ -0,0 +1,34 @@
+