1 | <?php |
||
21 | class Request implements RequestInterface |
||
22 | { |
||
23 | const INTEREST_ENTITY_ID = 'interest_id'; |
||
24 | const BOARD_ENTITY_ID = 'board_id'; |
||
25 | const COOKIE_NAME = 'pinterest_cookie'; |
||
26 | const PINNER_ENTITY_ID = 'user_id'; |
||
27 | |||
28 | protected $userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0'; |
||
29 | /** |
||
30 | * @var HttpInterface |
||
31 | */ |
||
32 | protected $http; |
||
33 | protected $loggedIn; |
||
34 | protected $cookieJar; |
||
35 | protected $options; |
||
36 | |||
37 | /** |
||
38 | * |
||
39 | * @var string |
||
40 | */ |
||
41 | protected $filePathToUpload; |
||
42 | |||
43 | public $csrfToken = ''; |
||
44 | |||
45 | /** |
||
46 | * Common headers needed for every query. |
||
47 | * |
||
48 | * @var array |
||
49 | */ |
||
50 | protected $requestHeaders = [ |
||
51 | 'Accept: application/json, text/javascript, */*; q=0.01', |
||
52 | 'Accept-Language: en-US,en;q=0.5', |
||
53 | 'DNT: 1', |
||
54 | 'Host: nl.pinterest.com', |
||
55 | 'X-Pinterest-AppState: active', |
||
56 | 'X-NEW-APP: 1', |
||
57 | 'X-APP-VERSION: 04cf8cc', |
||
58 | 'X-Requested-With: XMLHttpRequest', |
||
59 | ]; |
||
60 | |||
61 | /** |
||
62 | * @var string |
||
63 | */ |
||
64 | protected $postFileData; |
||
65 | |||
66 | /** |
||
67 | * @param HttpInterface $http |
||
68 | */ |
||
69 | public function __construct(HttpInterface $http) |
||
74 | |||
75 | /** |
||
76 | * Executes api call for follow or unfollow user. |
||
77 | * |
||
78 | * @param int $entityId |
||
79 | * @param string $entityName |
||
80 | * @param string $url |
||
81 | * |
||
82 | * @return array |
||
83 | */ |
||
84 | public function followMethodCall($entityId, $entityName, $url) |
||
102 | |||
103 | public function upload($pathToFile, $url) |
||
109 | |||
110 | /** |
||
111 | * Executes request to Pinterest API. |
||
112 | * |
||
113 | * @param string $resourceUrl |
||
114 | * @param string $postString |
||
115 | * |
||
116 | * @return array |
||
117 | */ |
||
118 | public function exec($resourceUrl, $postString = '') |
||
127 | |||
128 | /** |
||
129 | * Adds necessary curl options for query. |
||
130 | * |
||
131 | * @param string $postString POST query string |
||
132 | * |
||
133 | * @return $this |
||
134 | */ |
||
135 | protected function makeHttpOptions($postString = '') |
||
150 | |||
151 | /** |
||
152 | * @return array |
||
153 | */ |
||
154 | protected function setDefaultHttpOptions() |
||
168 | |||
169 | /** |
||
170 | * @param array $options |
||
171 | * |
||
172 | * @return mixed |
||
173 | */ |
||
174 | protected function addDefaultCsrfInfo($options) |
||
181 | |||
182 | /** |
||
183 | * Clear token information. |
||
184 | * |
||
185 | * @return $this |
||
186 | */ |
||
187 | public function clearToken() |
||
193 | |||
194 | /** |
||
195 | * Mark api as logged. |
||
196 | * @return $this |
||
197 | * @throws AuthException |
||
198 | */ |
||
199 | public function setLoggedIn() |
||
208 | |||
209 | /** |
||
210 | * Get log status. |
||
211 | * |
||
212 | * @return bool |
||
213 | */ |
||
214 | public function isLoggedIn() |
||
218 | |||
219 | /** |
||
220 | * @param $userAgent |
||
221 | * @return $this |
||
222 | */ |
||
223 | public function setUserAgent($userAgent) |
||
231 | |||
232 | /** |
||
233 | * Create request string. |
||
234 | * |
||
235 | * @param array $data |
||
236 | * @param string $sourceUrl |
||
237 | * @param array $bookmarks |
||
238 | * |
||
239 | * @return string |
||
240 | */ |
||
241 | public static function createQuery(array $data = [], $sourceUrl = '/', $bookmarks = []) |
||
247 | |||
248 | /** |
||
249 | * @param array|object $data |
||
250 | * @param string|null $sourceUrl |
||
251 | * @param array $bookmarks |
||
252 | * |
||
253 | * @return array |
||
254 | */ |
||
255 | public static function createRequestData(array $data = [], $sourceUrl = '/', $bookmarks = []) |
||
272 | |||
273 | /** |
||
274 | * @return array |
||
275 | */ |
||
276 | protected static function createEmptyRequestData() |
||
280 | |||
281 | /** |
||
282 | * @return array |
||
283 | */ |
||
284 | protected function getDefaultHttpHeaders() |
||
290 | |||
291 | /** |
||
292 | * If we are uploading file, we should build boundary form data. Otherwise |
||
293 | * it is simple urlencoded form. |
||
294 | * |
||
295 | * @return array |
||
296 | */ |
||
297 | protected function getContentTypeHeader() |
||
311 | |||
312 | protected function buildFilePostData($delimiter) |
||
324 | } |
||
325 |