@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Route4Me; |
| 3 | 3 | |
| 4 | - $vdir=$_SERVER['DOCUMENT_ROOT'].'/route4me/examples/'; |
|
| 4 | + $vdir = $_SERVER['DOCUMENT_ROOT'].'/route4me/examples/'; |
|
| 5 | 5 | |
| 6 | 6 | require $vdir.'/../vendor/autoload.php'; |
| 7 | 7 | //require __DIR__.'/../vendor/autoload.php';; |
@@ -1,7 +1,7 @@ |
||
| 1 | 1 | <?php |
| 2 | 2 | namespace Route4Me; |
| 3 | 3 | |
| 4 | - $vdir=$_SERVER['DOCUMENT_ROOT'].'/route4me/examples/'; |
|
| 4 | + $vdir = $_SERVER['DOCUMENT_ROOT'].'/route4me/examples/'; |
|
| 5 | 5 | |
| 6 | 6 | require $vdir.'/../vendor/autoload.php'; |
| 7 | 7 | //require __DIR__.'/../vendor/autoload.php';; |
@@ -167,16 +167,16 @@ |
||
| 167 | 167 | $this->_deviceId = $device->MyQDeviceId; |
| 168 | 168 | foreach ($device->Attributes as $attr) { |
| 169 | 169 | switch ($attr->AttributeDisplayName) { |
| 170 | - case 'desc': |
|
| 171 | - $this->_doorName = $attr->Value; |
|
| 172 | - break; |
|
| 173 | - case 'doorstate': |
|
| 174 | - $this->_doorState = $attr->Value; |
|
| 175 | - // UpdatedTime is a timestamp in ms, so we truncate |
|
| 176 | - $this->_doorStateTime = (int)$attr->UpdatedTime / 1000; |
|
| 177 | - break; |
|
| 178 | - default: |
|
| 179 | - continue; |
|
| 170 | + case 'desc': |
|
| 171 | + $this->_doorName = $attr->Value; |
|
| 172 | + break; |
|
| 173 | + case 'doorstate': |
|
| 174 | + $this->_doorState = $attr->Value; |
|
| 175 | + // UpdatedTime is a timestamp in ms, so we truncate |
|
| 176 | + $this->_doorStateTime = (int)$attr->UpdatedTime / 1000; |
|
| 177 | + break; |
|
| 178 | + default: |
|
| 179 | + continue; |
|
| 180 | 180 | } |
| 181 | 181 | } |
| 182 | 182 | } |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | * |
| 44 | 44 | * @return MyQ |
| 45 | 45 | */ |
| 46 | - public function __construct ($params = array()) { |
|
| 46 | + public function __construct($params = array()) { |
|
| 47 | 47 | // Overwrite class variables |
| 48 | 48 | foreach ($params as $k => $v) { |
| 49 | 49 | $this->$k = $v; |
| 50 | 50 | } |
| 51 | 51 | // Initialize cURL request headers |
| 52 | - if (sizeof($this->_headers) == 0) { |
|
| 53 | - $this->_headers = array ( |
|
| 52 | + if (sizeof($this->_headers)==0) { |
|
| 53 | + $this->_headers = array( |
|
| 54 | 54 | 'MyQApplicationId' => $this->appId, |
| 55 | 55 | 'Culture' => $this->culture, |
| 56 | 56 | 'Content-Type' => $this->contentType, |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * |
| 70 | 70 | * @return MyQ |
| 71 | 71 | */ |
| 72 | - public function login ($username = null, $password = null) { |
|
| 72 | + public function login($username = null, $password = null) { |
|
| 73 | 73 | // Set username/password if not null |
| 74 | 74 | if (!is_null($username)) { |
| 75 | 75 | $this->username = $username; |
@@ -85,15 +85,15 @@ discard block |
||
| 85 | 85 | if (is_null($this->password)) { |
| 86 | 86 | $error[] = 'password'; |
| 87 | 87 | } |
| 88 | - if (sizeof($error) > 0) { |
|
| 89 | - throw new MyQException('Missing required auth credential: ' . implode(',', $error)); |
|
| 88 | + if (sizeof($error)>0) { |
|
| 89 | + throw new MyQException('Missing required auth credential: '.implode(',', $error)); |
|
| 90 | 90 | } |
| 91 | 91 | $this->_login(); |
| 92 | 92 | } |
| 93 | - public function getState () { |
|
| 93 | + public function getState() { |
|
| 94 | 94 | $this->_getDetails(); |
| 95 | 95 | $timeInState = time() - $this->_doorStateTime; |
| 96 | - echo implode(',', array ( |
|
| 96 | + echo implode(',', array( |
|
| 97 | 97 | $this->_locationName, |
| 98 | 98 | $this->_doorName, |
| 99 | 99 | $this->_doorState, |
@@ -105,10 +105,10 @@ discard block |
||
| 105 | 105 | return $this->_getDetails(); |
| 106 | 106 | } |
| 107 | 107 | |
| 108 | - private function _init () { |
|
| 108 | + private function _init() { |
|
| 109 | 109 | if (!isset($this->_conn)) { |
| 110 | 110 | $this->_conn = curl_init(); |
| 111 | - curl_setopt_array($this->_conn, array ( |
|
| 111 | + curl_setopt_array($this->_conn, array( |
|
| 112 | 112 | CURLOPT_RETURNTRANSFER => true, |
| 113 | 113 | CURLOPT_ENCODING => "", |
| 114 | 114 | CURLOPT_MAXREDIRS => 10, |
@@ -123,14 +123,14 @@ discard block |
||
| 123 | 123 | } |
| 124 | 124 | $this->_setHeaders(); |
| 125 | 125 | } |
| 126 | - private function _setHeaders () { |
|
| 126 | + private function _setHeaders() { |
|
| 127 | 127 | $headers = array(); |
| 128 | 128 | foreach ($this->_headers as $k => $v) { |
| 129 | 129 | $headers[] = "$k: $v"; |
| 130 | 130 | } |
| 131 | 131 | curl_setopt($this->_conn, CURLOPT_HTTPHEADER, $headers); |
| 132 | 132 | } |
| 133 | - private function _login () { |
|
| 133 | + private function _login() { |
|
| 134 | 134 | $this->_init(); |
| 135 | 135 | curl_setopt($this->_conn, CURLOPT_CUSTOMREQUEST, 'POST'); |
| 136 | 136 | curl_setopt($this->_conn, CURLOPT_URL, $this->_loginUrl); |
@@ -138,27 +138,27 @@ discard block |
||
| 138 | 138 | curl_setopt($this->_conn, CURLOPT_POSTFIELDS, $post); |
| 139 | 139 | $output = curl_exec($this->_conn); |
| 140 | 140 | $data = json_decode($output); |
| 141 | - if ($data == false || !isset($data->SecurityToken)) { |
|
| 141 | + if ($data==false || !isset($data->SecurityToken)) { |
|
| 142 | 142 | throw new MyQException("Error processing login request: $output"); |
| 143 | 143 | } |
| 144 | 144 | $this->_headers['SecurityToken'] = $data->SecurityToken; |
| 145 | 145 | return $this; |
| 146 | 146 | } |
| 147 | - private function _getDetails () { |
|
| 147 | + private function _getDetails() { |
|
| 148 | 148 | $this->_init(); |
| 149 | 149 | curl_setopt($this->_conn, CURLOPT_CUSTOMREQUEST, 'GET'); |
| 150 | 150 | curl_setopt($this->_conn, CURLOPT_URL, $this->_getDeviceDetailUrl); |
| 151 | 151 | $output = curl_exec($this->_conn); |
| 152 | 152 | $data = json_decode($output); |
| 153 | - if ($data == false || !isset($data->Devices)) { |
|
| 153 | + if ($data==false || !isset($data->Devices)) { |
|
| 154 | 154 | throw new MyQException("Error fetching device details: $output"); |
| 155 | 155 | } |
| 156 | 156 | // Find our door device ID |
| 157 | 157 | foreach ($data->Devices as $device) { |
| 158 | - if (stripos($device->MyQDeviceTypeName, "Gateway") !== false) { |
|
| 158 | + if (stripos($device->MyQDeviceTypeName, "Gateway")!==false) { |
|
| 159 | 159 | // Find location name |
| 160 | 160 | foreach ($device->Attributes as $attr) { |
| 161 | - if ($attr->AttributeDisplayName == 'desc') { |
|
| 161 | + if ($attr->AttributeDisplayName=='desc') { |
|
| 162 | 162 | $this->_locationName = $attr->Value; |
| 163 | 163 | } |
| 164 | 164 | } |