1 | <?php |
||
11 | class DropboxRequest |
||
12 | { |
||
13 | |||
14 | /** |
||
15 | * Access Token to use for this request |
||
16 | * |
||
17 | * @var string |
||
18 | */ |
||
19 | protected $accessToken = null; |
||
20 | |||
21 | /** |
||
22 | * The HTTP method for this request |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $method = "GET"; |
||
27 | |||
28 | /** |
||
29 | * The params for this request |
||
30 | * |
||
31 | * @var array |
||
32 | */ |
||
33 | protected $params = null; |
||
34 | |||
35 | /** |
||
36 | * The Endpoint for this request |
||
37 | * |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $endpoint = null; |
||
41 | |||
42 | /** |
||
43 | * The Endpoint Type for this request |
||
44 | * |
||
45 | * @var string |
||
46 | */ |
||
47 | protected $endpointType = null; |
||
48 | |||
49 | /** |
||
50 | * The headers to send with this request |
||
51 | * |
||
52 | * @var array |
||
53 | */ |
||
54 | protected $headers = []; |
||
55 | |||
56 | /** |
||
57 | * File to upload |
||
58 | * |
||
59 | * @var \Kunnu\Dropbox\DropboxFile |
||
60 | */ |
||
61 | protected $file = null; |
||
62 | |||
63 | /** |
||
64 | * Content Type for the Request |
||
65 | * |
||
66 | * @var string |
||
67 | */ |
||
68 | protected $contentType = 'application/json'; |
||
69 | |||
70 | /** |
||
71 | * If the Response needs to be validated |
||
72 | * against being a valid JSON response. |
||
73 | * Set this to false when an endpoint or |
||
74 | * request has no return values. |
||
75 | * |
||
76 | * @var boolean |
||
77 | */ |
||
78 | protected $validateResponse = true; |
||
79 | |||
80 | |||
81 | /** |
||
82 | * Create a new DropboxRequest instance |
||
83 | * |
||
84 | * @param string $method HTTP Method of the Request |
||
85 | * @param string $endpoint API endpoint of the Request |
||
86 | * @param string $accessToken Access Token for the Request |
||
87 | * @param string $endpointType Endpoint type ['api'|'content'] |
||
88 | * @param mixed $params Request Params |
||
89 | * @param array $headers Headers to send along with the Request |
||
90 | */ |
||
91 | 49 | public function __construct($method, $endpoint, $accessToken, $endpointType = "api", array $params = [], array $headers = [], $contentType = null) |
|
104 | |||
105 | /** |
||
106 | * Get the Request Method |
||
107 | * |
||
108 | * @return string |
||
109 | */ |
||
110 | 49 | public function getMethod() |
|
114 | |||
115 | /** |
||
116 | * Set the Request Method |
||
117 | * |
||
118 | * @param string |
||
119 | * |
||
120 | * @return \Kunnu\Dropbox\DropboxRequest |
||
121 | */ |
||
122 | 49 | public function setMethod($method) |
|
128 | |||
129 | /** |
||
130 | * Get Access Token for the Request |
||
131 | * |
||
132 | * @return string |
||
133 | */ |
||
134 | 49 | public function getAccessToken() |
|
138 | |||
139 | /** |
||
140 | * Set Access Token for the Request |
||
141 | * |
||
142 | * @param string |
||
143 | * |
||
144 | * @return \Kunnu\Dropbox\DropboxRequest |
||
145 | */ |
||
146 | 49 | public function setAccessToken($accessToken) |
|
152 | |||
153 | /** |
||
154 | * Get the Endpoint of the Request |
||
155 | * |
||
156 | * @return string |
||
157 | */ |
||
158 | 49 | public function getEndpoint() |
|
162 | |||
163 | /** |
||
164 | * Set the Endpoint of the Request |
||
165 | * |
||
166 | * @param string |
||
167 | * |
||
168 | * @return \Kunnu\Dropbox\DropboxRequest |
||
169 | */ |
||
170 | 49 | public function setEndpoint($endpoint) |
|
176 | |||
177 | /** |
||
178 | * Get the Endpoint Type of the Request |
||
179 | * |
||
180 | * @return string |
||
181 | */ |
||
182 | 49 | public function getEndpointType() |
|
186 | |||
187 | /** |
||
188 | * Set the Endpoint Type of the Request |
||
189 | * |
||
190 | * @param string |
||
191 | * |
||
192 | * @return \Kunnu\Dropbox\DropboxRequest |
||
193 | */ |
||
194 | 49 | public function setEndpointType($endpointType) |
|
200 | |||
201 | /** |
||
202 | * Get the Content Type of the Request |
||
203 | * |
||
204 | * @return string |
||
205 | */ |
||
206 | 49 | public function getContentType() |
|
210 | |||
211 | /** |
||
212 | * Set the Content Type of the Request |
||
213 | * |
||
214 | * @param string |
||
215 | * |
||
216 | * @return \Kunnu\Dropbox\DropboxRequest |
||
217 | */ |
||
218 | 12 | public function setContentType($contentType) |
|
219 | { |
||
220 | 12 | $this->contentType = $contentType; |
|
221 | |||
222 | 12 | return $this; |
|
223 | } |
||
224 | |||
225 | /** |
||
226 | * Get Request Headers |
||
227 | * |
||
228 | * @return array |
||
229 | */ |
||
230 | 49 | public function getHeaders() |
|
234 | |||
235 | /** |
||
236 | * Set Request Headers |
||
237 | * |
||
238 | * @param array |
||
239 | * |
||
240 | * @return \Kunnu\Dropbox\DropboxRequest |
||
241 | */ |
||
242 | 49 | public function setHeaders(array $headers) |
|
248 | |||
249 | /** |
||
250 | * Get JSON Encoded Request Body |
||
251 | * |
||
252 | * @return \Kunnu\Dropbox\Http\RequestBodyJsonEncoded |
||
253 | */ |
||
254 | 39 | public function getJsonBody() |
|
258 | |||
259 | /** |
||
260 | * Get the Request Params |
||
261 | * |
||
262 | * @return array |
||
263 | */ |
||
264 | 49 | public function getParams() |
|
268 | |||
269 | /** |
||
270 | * Set the Request Params |
||
271 | * |
||
272 | * @param array |
||
273 | * |
||
274 | * @return \Kunnu\Dropbox\DropboxRequest |
||
275 | */ |
||
276 | 49 | public function setParams(array $params = []) |
|
287 | |||
288 | /** |
||
289 | * Get Stream Request Body |
||
290 | * |
||
291 | * @return \Kunnu\Dropbox\Http\RequestBodyStream |
||
292 | */ |
||
293 | 7 | public function getStreamBody() |
|
294 | { |
||
295 | 7 | return new RequestBodyStream($this->getFile()); |
|
296 | } |
||
297 | |||
298 | /** |
||
299 | * Get the File to be sent with the Request |
||
300 | * |
||
301 | * @return \Kunnu\Dropbox\DropboxFile |
||
302 | */ |
||
303 | 7 | public function getFile() |
|
304 | { |
||
305 | 7 | return $this->file; |
|
306 | } |
||
307 | |||
308 | /** |
||
309 | * Set the File to be sent with the Request |
||
310 | * |
||
311 | * @param \Kunnu\Dropbox\DropboxFile |
||
312 | * |
||
313 | * @return \Kunnu\Dropbox\DropboxRequest |
||
314 | */ |
||
315 | 7 | public function setFile(DropboxFile $file) |
|
316 | { |
||
317 | 7 | $this->file = $file; |
|
318 | |||
319 | 7 | return $this; |
|
320 | } |
||
321 | |||
322 | /** |
||
323 | * Returns true if Request has file to be uploaded |
||
324 | * |
||
325 | * @return boolean |
||
326 | */ |
||
327 | 10 | public function hasFile() |
|
328 | { |
||
329 | 10 | return !is_null($this->file) ? true : false; |
|
330 | } |
||
331 | |||
332 | /** |
||
333 | * Whether to validate response or not |
||
334 | * |
||
335 | * @return boolean |
||
336 | */ |
||
337 | 44 | public function validateResponse() |
|
341 | |||
342 | /** |
||
343 | * Process Params for the File parameter |
||
344 | * |
||
345 | * @param array $params Request Params |
||
346 | * |
||
347 | * @return array |
||
348 | */ |
||
349 | 49 | protected function processParams(array $params) |
|
370 | } |
||
371 |