1 | <?php |
||
21 | class Request implements RequestInterface |
||
22 | { |
||
23 | const COOKIE_NAME = 'pinterest_cookie'; |
||
24 | |||
25 | protected $userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0'; |
||
26 | /** |
||
27 | * @var HttpInterface |
||
28 | */ |
||
29 | protected $http; |
||
30 | protected $loggedIn; |
||
31 | protected $cookieJar; |
||
32 | protected $options; |
||
33 | |||
34 | /** |
||
35 | * |
||
36 | * @var string |
||
37 | */ |
||
38 | protected $filePathToUpload; |
||
39 | |||
40 | public $csrfToken = ''; |
||
41 | |||
42 | /** |
||
43 | * Common headers needed for every query. |
||
44 | * |
||
45 | * @var array |
||
46 | */ |
||
47 | protected $requestHeaders = [ |
||
48 | 'Accept: application/json, text/javascript, */*; q=0.01', |
||
49 | 'Accept-Language: en-US,en;q=0.5', |
||
50 | 'DNT: 1', |
||
51 | 'Host: nl.pinterest.com', |
||
52 | 'X-Pinterest-AppState: active', |
||
53 | 'X-NEW-APP: 1', |
||
54 | 'X-APP-VERSION: 04cf8cc', |
||
55 | 'X-Requested-With: XMLHttpRequest', |
||
56 | ]; |
||
57 | |||
58 | /** |
||
59 | * @var string |
||
60 | */ |
||
61 | protected $postFileData; |
||
62 | |||
63 | /** |
||
64 | * @param HttpInterface $http |
||
65 | */ |
||
66 | public function __construct(HttpInterface $http) |
||
71 | |||
72 | /** |
||
73 | * Executes api call for follow or unfollow user. |
||
74 | * |
||
75 | * @param int $entityId |
||
76 | * @param string $entityName |
||
77 | * @param string $url |
||
78 | * |
||
79 | * @return array |
||
80 | */ |
||
81 | public function followMethodCall($entityId, $entityName, $url) |
||
99 | |||
100 | public function upload($pathToFile, $url) |
||
106 | |||
107 | /** |
||
108 | * Executes request to Pinterest API. |
||
109 | * |
||
110 | * @param string $resourceUrl |
||
111 | * @param string $postString |
||
112 | * |
||
113 | * @return array |
||
114 | */ |
||
115 | public function exec($resourceUrl, $postString = '') |
||
124 | |||
125 | /** |
||
126 | * Adds necessary curl options for query. |
||
127 | * |
||
128 | * @param string $postString POST query string |
||
129 | * |
||
130 | * @return $this |
||
131 | */ |
||
132 | protected function makeHttpOptions($postString = '') |
||
147 | |||
148 | /** |
||
149 | * @return array |
||
150 | */ |
||
151 | protected function setDefaultHttpOptions() |
||
165 | |||
166 | /** |
||
167 | * @param array $options |
||
168 | * |
||
169 | * @return mixed |
||
170 | */ |
||
171 | protected function addDefaultCsrfInfo($options) |
||
178 | |||
179 | /** |
||
180 | * Clear token information. |
||
181 | * |
||
182 | * @return $this |
||
183 | */ |
||
184 | public function clearToken() |
||
185 | { |
||
186 | $this->csrfToken = CsrfHelper::DEFAULT_TOKEN; |
||
187 | |||
188 | return $this; |
||
189 | } |
||
190 | |||
191 | /** |
||
192 | * Mark api as logged. |
||
193 | * @return $this |
||
194 | * @throws AuthException |
||
195 | */ |
||
196 | public function setLoggedIn() |
||
205 | |||
206 | /** |
||
207 | * Get log status. |
||
208 | * |
||
209 | * @return bool |
||
210 | */ |
||
211 | public function isLoggedIn() |
||
215 | |||
216 | /** |
||
217 | * @param $userAgent |
||
218 | * @return $this |
||
219 | */ |
||
220 | public function setUserAgent($userAgent) |
||
228 | |||
229 | /** |
||
230 | * Create request string. |
||
231 | * |
||
232 | * @param array $data |
||
233 | * @param string $sourceUrl |
||
234 | * @param array $bookmarks |
||
235 | * |
||
236 | * @return string |
||
237 | */ |
||
238 | public static function createQuery(array $data = [], $sourceUrl = '/', $bookmarks = []) |
||
244 | |||
245 | /** |
||
246 | * @param array|object $data |
||
247 | * @param string|null $sourceUrl |
||
248 | * @param array $bookmarks |
||
249 | * |
||
250 | * @return array |
||
251 | */ |
||
252 | public static function createRequestData(array $data = [], $sourceUrl = '/', $bookmarks = []) |
||
269 | |||
270 | /** |
||
271 | * @return array |
||
272 | */ |
||
273 | protected function getDefaultHttpHeaders() |
||
279 | |||
280 | /** |
||
281 | * If we are uploading file, we should build boundary form data. Otherwise |
||
282 | * it is simple urlencoded form. |
||
283 | * |
||
284 | * @return array |
||
285 | */ |
||
286 | protected function getContentTypeHeader() |
||
300 | |||
301 | protected function buildFilePostData($delimiter) |
||
313 | } |
||
314 |