1 | <?php |
||
20 | class Request implements RequestInterface |
||
21 | { |
||
22 | const INTEREST_ENTITY_ID = 'interest_id'; |
||
23 | const BOARD_ENTITY_ID = 'board_id'; |
||
24 | const COOKIE_NAME = 'pinterest_cookie'; |
||
25 | const PINNER_ENTITY_ID = 'user_id'; |
||
26 | |||
27 | protected $userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0'; |
||
28 | /** |
||
29 | * @var HttpInterface |
||
30 | */ |
||
31 | protected $http; |
||
32 | protected $loggedIn; |
||
33 | protected $cookieJar; |
||
34 | protected $options; |
||
35 | |||
36 | public $csrfToken = ''; |
||
37 | |||
38 | /** |
||
39 | * Common headers needed for every query. |
||
40 | * |
||
41 | * @var array |
||
42 | */ |
||
43 | protected $requestHeaders = [ |
||
44 | 'Accept: application/json, text/javascript, */*; q=0.01', |
||
45 | 'Accept-Language: en-US,en;q=0.5', |
||
46 | 'DNT: 1', |
||
47 | 'Host: nl.pinterest.com', |
||
48 | 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8', |
||
49 | 'X-Pinterest-AppState: active', |
||
50 | 'X-NEW-APP: 1', |
||
51 | 'X-APP-VERSION: 04cf8cc', |
||
52 | 'X-Requested-With: XMLHttpRequest', |
||
53 | ]; |
||
54 | |||
55 | /** |
||
56 | * @param HttpInterface $http |
||
57 | */ |
||
58 | public function __construct(HttpInterface $http) |
||
63 | |||
64 | /** |
||
65 | * Executes api call for follow or unfollow user. |
||
66 | * |
||
67 | * @param int $entityId |
||
68 | * @param string $entityName |
||
69 | * @param string $url |
||
70 | * |
||
71 | * @return array |
||
72 | */ |
||
73 | public function followMethodCall($entityId, $entityName, $url) |
||
91 | |||
92 | /** |
||
93 | * Executes request to Pinterest API. |
||
94 | * |
||
95 | * @param string $resourceUrl |
||
96 | * @param string $postString |
||
97 | * |
||
98 | * @return array |
||
99 | */ |
||
100 | public function exec($resourceUrl, $postString = '') |
||
108 | |||
109 | /** |
||
110 | * Adds necessary curl options for query. |
||
111 | * |
||
112 | * @param string $postString POST query string |
||
113 | * |
||
114 | * @return $this |
||
115 | */ |
||
116 | protected function makeHttpOptions($postString = '') |
||
131 | |||
132 | /** |
||
133 | * @return array |
||
134 | */ |
||
135 | protected function setDefaultHttpOptions() |
||
149 | |||
150 | /** |
||
151 | * @param array $options |
||
152 | * |
||
153 | * @return mixed |
||
154 | */ |
||
155 | protected function addDefaultCsrfInfo($options) |
||
162 | |||
163 | /** |
||
164 | * Clear token information. |
||
165 | * |
||
166 | * @return $this |
||
167 | */ |
||
168 | public function clearToken() |
||
174 | |||
175 | /** |
||
176 | * Mark api as logged. |
||
177 | * @return $this |
||
178 | * @throws AuthException |
||
179 | */ |
||
180 | public function setLoggedIn() |
||
189 | |||
190 | /** |
||
191 | * Get log status. |
||
192 | * |
||
193 | * @return bool |
||
194 | */ |
||
195 | public function isLoggedIn() |
||
199 | |||
200 | /** |
||
201 | * @param $userAgent |
||
202 | * @return $this |
||
203 | */ |
||
204 | public function setUserAgent($userAgent) |
||
212 | |||
213 | /** |
||
214 | * Create request string. |
||
215 | * |
||
216 | * @param array $data |
||
217 | * @param string $sourceUrl |
||
218 | * @param array $bookmarks |
||
219 | * |
||
220 | * @return string |
||
221 | */ |
||
222 | public static function createQuery(array $data = [], $sourceUrl = '/', $bookmarks = []) |
||
228 | |||
229 | /** |
||
230 | * @param array|object $data |
||
231 | * @param string|null $sourceUrl |
||
232 | * @param array $bookmarks |
||
233 | * |
||
234 | * @return array |
||
235 | */ |
||
236 | public static function createRequestData(array $data = [], $sourceUrl = '/', $bookmarks = []) |
||
253 | |||
254 | /** |
||
255 | * @return array |
||
256 | */ |
||
257 | protected static function createEmptyRequestData() |
||
261 | |||
262 | /** |
||
263 | * @return array |
||
264 | */ |
||
265 | protected function getDefaultHttpHeaders() |
||
269 | } |
||
270 |