forked from tomrosenback/botvac
-
Notifications
You must be signed in to change notification settings - Fork 0
/
NeatoBotvacClient.php
67 lines (52 loc) · 1.47 KB
/
NeatoBotvacClient.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
56
57
58
59
60
61
62
63
64
65
66
67
<?php
/*
* Neato Botvac Client
* Used to authorize the client and to fetch registered robots for the client
*
* PHP port based on https://github.com/kangguru/botvac
*
* Author: Tom Rosenback [email protected] 2016
*/
require_once("NeatoBotvacApi.php");
class NeatoBotvacClient {
protected $baseUrl = "https://beehive.neatocloud.com";
public $token;
public function __construct($token = false, $vendor="neato") {
$this->token = $token;
switch ($vendor) {
case "vorwerk":
$this->baseUrl = "https://vorwerk-beehive-production.herokuapp.com";
break;
}
}
public function authorize($email, $password, $force = false) {
if($this->token === false || $force === true) {
$result = NeatoBotvacApi::request($this->baseUrl."/sessions",
array(
"platform" => "ios",
"email" => $email,
"token" => bin2hex(openssl_random_pseudo_bytes(32)),
"password" => $password
)
);
if(isset($result["access_token"])) {
$this->token = $result["access_token"];
}
}
return $this->token;
}
public function reauthorize($email, $password) {
return $this->authorize($email, $password, true);
}
public function getRobots($token = false) {
$result = array("message" => "no token");
if($token !== false) {
$this->token = $token;
}
if($this->token !== false) {
$result = NeatoBotvacApi::request($this->baseUrl."/dashboard", null, "GET", array("Authorization: Token token=".$this->token));
}
return $result;
}
}
?>