1 | <?php |
||
19 | class Request |
||
20 | { |
||
21 | /** |
||
22 | * @var HttpClient |
||
23 | */ |
||
24 | protected $httpClient; |
||
25 | |||
26 | /** |
||
27 | * @var bool |
||
28 | */ |
||
29 | protected $loggedIn; |
||
30 | |||
31 | /** |
||
32 | * |
||
33 | * @var string |
||
34 | */ |
||
35 | protected $filePathToUpload; |
||
36 | |||
37 | /** |
||
38 | * @var string |
||
39 | */ |
||
40 | protected $csrfToken = ''; |
||
41 | |||
42 | /** |
||
43 | * @var string |
||
44 | */ |
||
45 | protected $postFileData; |
||
46 | |||
47 | /** |
||
48 | * @var array|null |
||
49 | */ |
||
50 | protected $lastError; |
||
51 | |||
52 | |||
53 | /** |
||
54 | * Common headers needed for every query. |
||
55 | * |
||
56 | * @var array |
||
57 | */ |
||
58 | protected $requestHeaders = [ |
||
59 | 'Accept: application/json, text/javascript, */*; q=0.01', |
||
60 | 'Accept-Language: en-US,en;q=0.5', |
||
61 | 'DNT: 1', |
||
62 | 'X-Pinterest-AppState: active', |
||
63 | 'X-NEW-APP: 1', |
||
64 | 'X-APP-VERSION: 04cf8cc', |
||
65 | 'X-Requested-With: XMLHttpRequest', |
||
66 | ]; |
||
67 | |||
68 | /** |
||
69 | * @param HttpClient $http |
||
70 | */ |
||
71 | public function __construct(HttpClient $http) |
||
76 | |||
77 | /** |
||
78 | * @param string $pathToFile |
||
79 | * @param string $url |
||
80 | * @return array |
||
81 | * @throws InvalidRequestException |
||
82 | */ |
||
83 | public function upload($pathToFile, $url) |
||
89 | |||
90 | /** |
||
91 | * Executes request to Pinterest API. |
||
92 | * |
||
93 | * @param string $resourceUrl |
||
94 | * @param string $postString |
||
95 | * |
||
96 | * @return Response |
||
97 | */ |
||
98 | public function exec($resourceUrl, $postString = '') |
||
110 | |||
111 | /** |
||
112 | * @return array |
||
113 | */ |
||
114 | protected function getHttpHeaders() |
||
123 | |||
124 | |||
125 | /** |
||
126 | * Clear token information. |
||
127 | * |
||
128 | * @return $this |
||
129 | */ |
||
130 | public function clearToken() |
||
136 | |||
137 | /** |
||
138 | * Mark api as logged. |
||
139 | * @return $this |
||
140 | * @throws AuthException |
||
141 | */ |
||
142 | public function login() |
||
147 | |||
148 | public function logout() |
||
153 | |||
154 | /** |
||
155 | * Get log status. |
||
156 | * |
||
157 | * @return bool |
||
158 | */ |
||
159 | public function isLoggedIn() |
||
163 | |||
164 | /** |
||
165 | * Create request string. |
||
166 | * |
||
167 | * @param array $data |
||
168 | * @param array $bookmarks |
||
169 | * |
||
170 | * @return string |
||
171 | */ |
||
172 | public static function createQuery(array $data = [], $bookmarks = []) |
||
179 | |||
180 | /** |
||
181 | * @param array|object $data |
||
182 | * @param array $bookmarks |
||
183 | * |
||
184 | * @return array |
||
185 | */ |
||
186 | public static function createRequestData(array $data = [], $bookmarks = []) |
||
203 | |||
204 | public function setTokenFromCookies() |
||
213 | |||
214 | /** |
||
215 | * @return array |
||
216 | */ |
||
217 | protected function getDefaultHttpHeaders() |
||
228 | |||
229 | /** |
||
230 | * If we are uploading file, we should build boundary form data. Otherwise |
||
231 | * it is simple urlencoded form. |
||
232 | * |
||
233 | * @return array |
||
234 | */ |
||
235 | protected function getContentTypeHeader() |
||
241 | |||
242 | /** |
||
243 | * @param string $delimiter |
||
244 | * @return $this |
||
245 | */ |
||
246 | protected function buildFilePostData($delimiter) |
||
258 | |||
259 | protected function makeHeadersForUpload() |
||
269 | |||
270 | /** |
||
271 | * @param string $res |
||
272 | * @return Response |
||
273 | */ |
||
274 | protected function processResponse($res) |
||
284 | |||
285 | /** |
||
286 | * @return array|null |
||
287 | */ |
||
288 | public function getLastError() |
||
292 | |||
293 | /** |
||
294 | * @return HttpClient |
||
295 | */ |
||
296 | public function getHttpClient() |
||
300 | } |
||
301 |