1 | <?php |
||
9 | class DropboxClient |
||
10 | { |
||
11 | /** |
||
12 | * Dropbox API Root URL. |
||
13 | * |
||
14 | * @const string |
||
15 | */ |
||
16 | const BASE_PATH = 'https://api.dropboxapi.com/2'; |
||
17 | |||
18 | /** |
||
19 | * Dropbox API Content Root URL. |
||
20 | * |
||
21 | * @const string |
||
22 | */ |
||
23 | const CONTENT_PATH = 'https://content.dropboxapi.com/2'; |
||
24 | |||
25 | /** |
||
26 | * DropboxHttpClientInterface Implementation |
||
27 | * |
||
28 | * @var \Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface |
||
29 | */ |
||
30 | protected $httpClient; |
||
31 | |||
32 | /** |
||
33 | * Create a new DropboxClient instance |
||
34 | * |
||
35 | * @param DropboxHttpClientInterface $httpClient |
||
36 | */ |
||
37 | 58 | public function __construct(DropboxHttpClientInterface $httpClient) |
|
42 | |||
43 | /** |
||
44 | * Get the HTTP Client |
||
45 | * |
||
46 | * @return \Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface $httpClient |
||
47 | */ |
||
48 | 49 | public function getHttpClient() |
|
52 | |||
53 | /** |
||
54 | * Set the HTTP Client |
||
55 | * |
||
56 | * @param \Kunnu\Dropbox\Http\Clients\DropboxHttpClientInterface $httpClient |
||
57 | * |
||
58 | * @return \Kunnu\Dropbox\DropboxClient |
||
59 | */ |
||
60 | 58 | public function setHttpClient(DropboxHttpClientInterface $httpClient) |
|
66 | |||
67 | /** |
||
68 | * Get the API Base Path. |
||
69 | * |
||
70 | * @return string API Base Path |
||
71 | */ |
||
72 | 49 | public function getBasePath() |
|
76 | |||
77 | /** |
||
78 | * Get the API Content Path. |
||
79 | * |
||
80 | * @return string API Content Path |
||
81 | */ |
||
82 | 10 | public function getContentPath() |
|
83 | { |
||
84 | 10 | return static::CONTENT_PATH; |
|
85 | } |
||
86 | |||
87 | /** |
||
88 | * Get the Authorization Header with the Access Token. |
||
89 | * |
||
90 | * @param string $accessToken Access Token |
||
91 | * |
||
92 | * @return array Authorization Header |
||
93 | */ |
||
94 | 49 | protected function buildAuthHeader($accessToken = "") |
|
98 | |||
99 | /** |
||
100 | * Get the Content Type Header. |
||
101 | * |
||
102 | * @param string $contentType Request Content Type |
||
103 | * |
||
104 | * @return array Content Type Header |
||
105 | */ |
||
106 | 49 | protected function buildContentTypeHeader($contentType = "") |
|
110 | |||
111 | /** |
||
112 | * Build URL for the Request |
||
113 | * |
||
114 | * @param string $endpoint Relative API endpoint |
||
115 | * @param string $type Endpoint Type |
||
116 | * |
||
117 | * @link https://www.dropbox.com/developers/documentation/http/documentation#formats Request and response formats |
||
118 | * |
||
119 | * @return string The Full URL to the API Endpoints |
||
120 | */ |
||
121 | 49 | protected function buildUrl($endpoint = '', $type = 'api') |
|
135 | |||
136 | /** |
||
137 | * Send the Request to the Server and return the Response |
||
138 | * |
||
139 | * @param DropboxRequest $request |
||
140 | * @param DropboxResponse $response |
||
141 | * |
||
142 | * @return \Kunnu\Dropbox\DropboxResponse |
||
143 | * |
||
144 | * @throws \Kunnu\Dropbox\Exceptions\DropboxClientException |
||
145 | */ |
||
146 | 49 | public function sendRequest(DropboxRequest $request, DropboxResponse $response = null) |
|
174 | |||
175 | /** |
||
176 | * Prepare a Request before being sent to the HTTP Client |
||
177 | * |
||
178 | * @param \Kunnu\Dropbox\DropboxRequest $request |
||
179 | * |
||
180 | * @return array [Request URL, Request Headers, Request Body] |
||
181 | */ |
||
182 | 49 | protected function prepareRequest(DropboxRequest $request) |
|
226 | } |
||
227 |