1 | <?php |
||
20 | class Request |
||
21 | { |
||
22 | const COOKIE_NAME = 'pinterest_cookie'; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0'; |
||
28 | |||
29 | /** |
||
30 | * @var HttpInterface |
||
31 | */ |
||
32 | protected $http; |
||
33 | |||
34 | /** |
||
35 | * @var bool |
||
36 | */ |
||
37 | protected $loggedIn; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $cookieJar; |
||
43 | |||
44 | /** |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $options; |
||
48 | |||
49 | /** |
||
50 | * |
||
51 | * @var string |
||
52 | */ |
||
53 | protected $filePathToUpload; |
||
54 | |||
55 | /** |
||
56 | * @var string |
||
57 | */ |
||
58 | protected $csrfToken = ''; |
||
59 | |||
60 | /** |
||
61 | * Common headers needed for every query. |
||
62 | * |
||
63 | * @var array |
||
64 | */ |
||
65 | protected $requestHeaders = [ |
||
66 | 'Accept: application/json, text/javascript, */*; q=0.01', |
||
67 | 'Accept-Language: en-US,en;q=0.5', |
||
68 | 'DNT: 1', |
||
69 | 'Host: nl.pinterest.com', |
||
70 | 'X-Pinterest-AppState: active', |
||
71 | 'X-NEW-APP: 1', |
||
72 | 'X-APP-VERSION: 04cf8cc', |
||
73 | 'X-Requested-With: XMLHttpRequest', |
||
74 | ]; |
||
75 | |||
76 | /** |
||
77 | * @var string |
||
78 | */ |
||
79 | protected $postFileData; |
||
80 | |||
81 | /** |
||
82 | * @param HttpInterface $http |
||
83 | */ |
||
84 | public function __construct(HttpInterface $http) |
||
90 | |||
91 | /** |
||
92 | * Executes api call for follow or unfollow user. |
||
93 | * |
||
94 | * @param int $entityId |
||
95 | * @param string $entityName |
||
96 | * @param string $url |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | public function followMethodCall($entityId, $entityName, $url) |
||
118 | |||
119 | /** |
||
120 | * @param string $pathToFile |
||
121 | * @param string $url |
||
122 | * |
||
123 | * @return array |
||
124 | */ |
||
125 | public function upload($pathToFile, $url) |
||
131 | |||
132 | /** |
||
133 | * Executes request to Pinterest API. |
||
134 | * |
||
135 | * @param string $resourceUrl |
||
136 | * @param string $postString |
||
137 | * |
||
138 | * @return array |
||
139 | */ |
||
140 | public function exec($resourceUrl, $postString = '') |
||
149 | |||
150 | /** |
||
151 | * Adds necessary curl options for query. |
||
152 | * |
||
153 | * @param string $postString POST query string |
||
154 | * |
||
155 | * @return $this |
||
156 | */ |
||
157 | protected function makeHttpOptions($postString = '') |
||
172 | |||
173 | /** |
||
174 | * @return array |
||
175 | */ |
||
176 | protected function setDefaultHttpOptions() |
||
190 | |||
191 | /** |
||
192 | * @param array $options |
||
193 | * |
||
194 | * @return mixed |
||
195 | */ |
||
196 | protected function addDefaultCsrfInfo($options) |
||
203 | |||
204 | /** |
||
205 | * Clear token information. |
||
206 | * |
||
207 | * @return $this |
||
208 | */ |
||
209 | public function clearToken() |
||
215 | |||
216 | /** |
||
217 | * Mark api as logged. |
||
218 | * @return $this |
||
219 | * @throws AuthException |
||
220 | */ |
||
221 | public function login() |
||
226 | |||
227 | public function logout() |
||
232 | |||
233 | /** |
||
234 | * Get log status. |
||
235 | * |
||
236 | * @return bool |
||
237 | */ |
||
238 | public function isLoggedIn() |
||
242 | |||
243 | /** |
||
244 | * @param $userAgent |
||
245 | * @return $this |
||
246 | */ |
||
247 | public function setUserAgent($userAgent) |
||
255 | |||
256 | /** |
||
257 | * Create request string. |
||
258 | * |
||
259 | * @param array $data |
||
260 | * @param array $bookmarks |
||
261 | * |
||
262 | * @return string |
||
263 | */ |
||
264 | public static function createQuery(array $data = [], $bookmarks = []) |
||
271 | |||
272 | /** |
||
273 | * @param array|object $data |
||
274 | * @param array $bookmarks |
||
275 | * |
||
276 | * @return array |
||
277 | */ |
||
278 | public static function createRequestData(array $data = [], $bookmarks = []) |
||
295 | |||
296 | public function setTokenFromCookies() |
||
305 | |||
306 | /** |
||
307 | * @return array |
||
308 | */ |
||
309 | protected function getDefaultHttpHeaders() |
||
317 | |||
318 | /** |
||
319 | * If we are uploading file, we should build boundary form data. Otherwise |
||
320 | * it is simple urlencoded form. |
||
321 | * |
||
322 | * @return array |
||
323 | */ |
||
324 | protected function getContentTypeHeader() |
||
330 | |||
331 | /** |
||
332 | * @param string $delimiter |
||
333 | * @return $this |
||
334 | */ |
||
335 | protected function buildFilePostData($delimiter) |
||
347 | |||
348 | protected function makeHeadersForUpload() |
||
358 | } |
||
359 |