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 | * @param string|null $userAgent |
||
58 | */ |
||
59 | public function __construct(HttpInterface $http, $userAgent = null) |
||
67 | |||
68 | /** |
||
69 | * Executes api call for follow or unfollow user |
||
70 | * |
||
71 | * @param int $entityId |
||
72 | * @param string $entityName |
||
73 | * @param string $url |
||
74 | * @return array |
||
75 | */ |
||
76 | public function followMethodCall($entityId, $entityName, $url) |
||
94 | |||
95 | /** |
||
96 | * Executes request to Pinterest API |
||
97 | * |
||
98 | * @param string $resourceUrl |
||
99 | * @param string $postString |
||
100 | * @return array |
||
101 | */ |
||
102 | public function exec($resourceUrl, $postString = "") |
||
111 | |||
112 | /** |
||
113 | * Adds necessary curl options for query |
||
114 | * |
||
115 | * @param string $postString POST query string |
||
116 | * @return $this |
||
117 | */ |
||
118 | protected function makeHttpOptions($postString = "") |
||
133 | |||
134 | /** |
||
135 | * Clear token information |
||
136 | * @return $this |
||
137 | */ |
||
138 | public function clearToken() |
||
144 | |||
145 | /** |
||
146 | * Mark api as logged |
||
147 | * |
||
148 | * @return $this |
||
149 | */ |
||
150 | public function setLoggedIn() |
||
159 | |||
160 | /** |
||
161 | * Get log status |
||
162 | * |
||
163 | * @return bool |
||
164 | */ |
||
165 | public function isLoggedIn() |
||
169 | |||
170 | /** |
||
171 | * @param array|object $data |
||
172 | * @param string|null $sourceUrl |
||
173 | * @param array $bookmarks |
||
174 | * @return array |
||
175 | */ |
||
176 | public static function createRequestData($data = [], $sourceUrl = '/', $bookmarks = []) |
||
193 | |||
194 | /** |
||
195 | * @return array |
||
196 | */ |
||
197 | protected static function createEmptyRequestData() |
||
201 | |||
202 | /** |
||
203 | * @return array |
||
204 | */ |
||
205 | protected function setDefaultHttpOptions() |
||
219 | |||
220 | /** |
||
221 | * @return array |
||
222 | */ |
||
223 | protected function getDefaultHttpHeaders() |
||
227 | |||
228 | /** |
||
229 | * @param array $options |
||
230 | * @return mixed |
||
231 | */ |
||
232 | protected function addDefaultCsrfInfo($options) |
||
239 | } |
||
240 |