-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patheHorecaClass.php
More file actions
76 lines (62 loc) · 1.85 KB
/
eHorecaClass.php
File metadata and controls
76 lines (62 loc) · 1.85 KB
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
68
69
70
71
72
73
74
75
76
<?php
function httpRequest($url, $data, $method="post", $verbose=false) {
if ($verbose) echo "\r\nURL: ".$url."\r\n";
if ($verbose) echo "\r\nDATA: ".print_r($data, true)."\r\n";
$curl = curl_init($url);
if (strcmp($method, "post") === 0) {
curl_setopt($curl, CURLOPT_POST, true);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($data));
} else if (strcmp($method, "get") === 0)
curl_setopt($curl, CURLOPT_HTTPHEADER, array(
'Content-Type: application/json, text/plain, */*',
'Authorization: Bearer '. $data["token"]
));
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
if ($verbose) curl_setopt($curl, CURLOPT_VERBOSE, true);
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
// Begin Class "eHoreca"
class eHoreca {
// Variable declaration
private $userId;
private $apiURL;
private $token = Null;
// Class Constructor
public function __construct($_apiURL) {
$this->apiURL = $_apiURL;
$this->token = Null;
}
// Class Destructor
public function __destruct() {
}
// Class Connect
public function connect($email, $password) {
$reply = json_decode(httpRequest($this->apiURL."login", array("email" => $email, "password" => $password)), true);
$this->token = $reply['token'];
$this->userId = $reply['id'];
}
public function getToken() {
return $this->token;
}
public function getUserId() {
return $this->userId;
}
public function printAllVars() {
$class_vars = get_class_vars(get_class($this));
foreach ($class_vars as $name => $value) {
echo $name." : ".$this->$name."\n";
}
}
//Include in the
public function getEndPoint($endPoint, $inputData=array()) {
$inputData["token"] = $this->token;
if ($this->token !== Null)
return (json_decode(httpRequest($this->apiURL.$endPoint, $inputData, "get", false), true));
else
return false;
}
}
// End Class "eHoreca"
?>