1 | <?php |
||
24 | class Client |
||
25 | { |
||
26 | /** |
||
27 | * The configuration details for connection |
||
28 | * @var array |
||
29 | */ |
||
30 | protected $config = array(); |
||
31 | |||
32 | /** |
||
33 | * The API Key to use |
||
34 | * @var string |
||
35 | */ |
||
36 | protected $api_key = null; |
||
37 | |||
38 | /** |
||
39 | * The API Secret to use |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $api_secret = null; |
||
43 | |||
44 | /** |
||
45 | * The URL to the Backup Pro API endpoint |
||
46 | * @var string |
||
47 | */ |
||
48 | protected $site_url = null; |
||
49 | |||
50 | /** |
||
51 | * The debug information |
||
52 | * @var string |
||
53 | */ |
||
54 | protected $debug_info = array(); |
||
55 | |||
56 | /** |
||
57 | * The Curl handle |
||
58 | * @var resource |
||
59 | */ |
||
60 | protected $curl_handle = null; |
||
61 | |||
62 | /** |
||
63 | * The HTTP verb names |
||
64 | * @var string |
||
65 | */ |
||
66 | const HTTP_METHOD_GET = 'GET'; |
||
67 | const HTTP_METHOD_POST = 'POST'; |
||
68 | const HTTP_METHOD_PUT = 'PUT'; |
||
69 | const HTTP_METHOD_DELETE = 'DELETE'; |
||
70 | |||
71 | /** |
||
72 | * Sets it up |
||
73 | * @param array $config |
||
74 | */ |
||
75 | public function __construct(array $config = array()) |
||
91 | |||
92 | /** |
||
93 | * Returns the config |
||
94 | * @return array |
||
95 | */ |
||
96 | public function getConfig() |
||
100 | |||
101 | /** |
||
102 | * Sets the API key to use for authentication |
||
103 | * @param string $key |
||
104 | * @return \JargerApp\Rest\Client |
||
105 | */ |
||
106 | public function setApiKey($key) |
||
111 | |||
112 | /** |
||
113 | * Returns the API key |
||
114 | * @return string |
||
115 | */ |
||
116 | public function getApiKey() |
||
120 | |||
121 | /** |
||
122 | * Sets the API secret to use for authentication |
||
123 | * @param string $secret |
||
124 | * @return \JargerApp\Rest\Client |
||
125 | */ |
||
126 | public function setApiSecret($secret) |
||
131 | |||
132 | /** |
||
133 | * Returns the API secret |
||
134 | * @return string |
||
135 | */ |
||
136 | public function getApiSecret() |
||
140 | |||
141 | /** |
||
142 | * Sets the Backup Pro REST API site URL |
||
143 | * @param string $site_url |
||
144 | * @return \JargerApp\Rest\Client |
||
145 | */ |
||
146 | public function setSiteUrl($site_url) |
||
151 | |||
152 | /** |
||
153 | * Returns the Backup Pro REST API site URL |
||
154 | * @param string $endpoint |
||
155 | * @return string |
||
156 | */ |
||
157 | public function getSiteUrl($endpoint = '', array $query = array()) |
||
165 | |||
166 | /** |
||
167 | * Send a POST request |
||
168 | * @param string $endpoint The API endpoint |
||
169 | * @param array $payload Data to submit |
||
170 | */ |
||
171 | public function post($endpoint, array $payload = array()) |
||
175 | |||
176 | /** |
||
177 | * Sends a GET request |
||
178 | * @param string $endpoint The API endpoint |
||
179 | * @param array $payload |
||
180 | */ |
||
181 | public function get($endpoint, array $payload = array()) |
||
185 | |||
186 | /** |
||
187 | * PUT to an authenciated API endpoint w/ payload |
||
188 | * |
||
189 | * @param string $endpoint |
||
190 | * @param array $payload |
||
191 | * @return array |
||
192 | */ |
||
193 | public function put($endpoint, array $payload = array()) |
||
197 | |||
198 | /** |
||
199 | * Performs a DELETE request |
||
200 | * @param string $endpoint |
||
201 | * @param array $payload |
||
202 | * @return bool |
||
203 | */ |
||
204 | public function delete($endpoint, array $payload = array()) |
||
208 | |||
209 | /** |
||
210 | * Sets up the Hmac authentication headers and dispatches the request |
||
211 | * @param string $endpoint The API endpoing we want |
||
212 | * @param array $payload Any data to send along |
||
213 | * @param string $method The HTTP method |
||
214 | * @return bool |
||
215 | */ |
||
216 | public function fetch($endpoint, array $payload = array(), $method = 'GET') |
||
238 | |||
239 | /** |
||
240 | * Returns the debug data |
||
241 | * @return array |
||
242 | */ |
||
243 | public function getDebugInfo() |
||
247 | |||
248 | /** |
||
249 | * Make a CURL request |
||
250 | * |
||
251 | * @param string $url |
||
252 | * @param array $payload |
||
253 | * @param string $method |
||
254 | * @param array $headers |
||
255 | * @param array $curl_options |
||
256 | * @throws \RuntimeException |
||
257 | * @return array |
||
258 | */ |
||
259 | protected function request($url, array $payload = array(), $method = 'GET', array $headers = array(), array $curl_options = array()) |
||
310 | |||
311 | |||
312 | protected function getCurlHandle() |
||
319 | |||
320 | public function __destruct() |
||
326 | } |