-
Notifications
You must be signed in to change notification settings - Fork 1
/
bucky-box-api-wrapper-base.php
68 lines (49 loc) · 1.71 KB
/
bucky-box-api-wrapper-base.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
68
<?php
/**
* Encapsulate some utility functions
*/
class BuckyBoxApiBase {
function __construct($key, $secret) {
$this->api_key = $key;
$this->api_secret = $secret;
}
protected function getHelper($url) {
$this->curl = new BuckyBoxCurl($this->api_key, $this->api_secret);
return $this->curl->get($url);
}
protected function getFullUrl($url) {
return BuckyBoxApiWrapper::$api_base_url . $url;
}
}
class BuckyBoxCurl {
function __construct($key, $secret) {
$this->api_key = $key;
$this->api_secret = $secret;
}
public function get($url) {
$this->curl = curl_init($url);
$this->setBasicCurlOptions();
$this->doCurlSession();
return [ $this->result_status , json_decode($this->response) ];
}
public function post($params, $url) {
d($params);
$this->curl = curl_init($url);
$this->setBasicCurlOptions();
curl_setopt($this->curl, CURLOPT_POST, true);
curl_setopt($this->curl, CURLOPT_POSTFIELDS, $params);
$this->doCurlSession();
return [ $this->result_status , json_decode($this->response) ];
}
protected function setBasicCurlOptions() {
curl_setopt($this->curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($this->curl, CURLOPT_USERAGENT, 'Bucky Box PHP API Wrapper');
curl_setopt($this->curl, CURLOPT_HTTPHEADER, [ 'API-Key: ' . $this->api_key, 'API-Secret: ' . $this->api_secret ]);
}
protected function doCurlSession() {
$this->response = curl_exec($this->curl);
$this->result_status = curl_getinfo($this->curl, CURLINFO_HTTP_CODE);
curl_close($this->curl);
}
}
?>