-
Notifications
You must be signed in to change notification settings - Fork 1
/
curl.php
55 lines (46 loc) · 1.71 KB
/
curl.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
class ThingSee {
const URL_MAX_LENGTH = 2050;
private $accountAuthUuid;
private $accountAuthToken;
private $timestamp;
private $url;
private $email;
private $password;
private $deviceUuid;
public function __construct(){
$passwords = new Passwords();
$this->url = $passwords->getUrl();
$this->email = $passwords->getEmail();
$this->password = $passwords->getPassword();
$this->deviceUuid = $passwords->getDeviceUuid();
}
public function getToken() {
$data = array("email" => $this->email, "password" => $this->password);
$data_string = json_encode($data);
$ch = curl_init($this->url);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "POST");
curl_setopt($ch, CURLOPT_POSTFIELDS, $data_string);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json',
'Content-Length: ' . strlen($data_string))
);
$result = json_decode(curl_exec($ch));
$this->accountAuthToken = $result->accountAuthToken;
$this->accountAuthUuid = $result->accountAuthUuid;
$this->timestamp = $result->timestamp;
curl_close($ch);
}
public function getData() {
$ch = curl_init("http://api.thingsee.com/v2//events/".$this->deviceUuid);
curl_setopt($ch, CURLOPT_CUSTOMREQUEST, "GET");
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
'Authorization: Bearer ' . $this->accountAuthToken
));
$result = json_decode(curl_exec($ch));
curl_close($ch);
return $result;
}
}