1 | <?php |
||
20 | class Request implements RequestInterface |
||
21 | { |
||
22 | const INTEREST_ENTITY_ID = 'interest_id'; |
||
23 | const BOARD_ENTITY_ID = 'board_id'; |
||
24 | const PINNER_ENTITY_ID = 'user_id'; |
||
25 | |||
26 | protected $userAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/31.0'; |
||
27 | const COOKIE_NAME = 'pinterest_cookie'; |
||
28 | /** |
||
29 | * @var HttpInterface |
||
30 | */ |
||
31 | protected $http; |
||
32 | protected $loggedIn; |
||
33 | protected $cookieJar; |
||
34 | |||
35 | public $csrfToken = ""; |
||
36 | |||
37 | /** |
||
38 | * Common headers needed for every query |
||
39 | * |
||
40 | * @var array |
||
41 | */ |
||
42 | protected $requestHeaders = [ |
||
43 | 'Host: www.pinterest.com', |
||
44 | 'Accept: application/json, text/javascript, */*; q=0.01', |
||
45 | 'Accept-Language: en-US,en;q=0.5', |
||
46 | 'DNT: 1', |
||
47 | 'Content-Type: application/x-www-form-urlencoded; charset=UTF-8', |
||
48 | 'X-Pinterest-AppState: active', |
||
49 | 'X-NEW-APP: 1', |
||
50 | 'X-APP-VERSION: 04cf8cc', |
||
51 | 'X-Requested-With: XMLHttpRequest', |
||
52 | ]; |
||
53 | |||
54 | /** |
||
55 | * @param HttpInterface $http |
||
56 | */ |
||
57 | public function __construct(HttpInterface $http) |
||
66 | |||
67 | /** |
||
68 | * Executes api call for follow or unfollow user |
||
69 | * |
||
70 | * @param int $entityId |
||
71 | * @param string $entityName |
||
72 | * @param string $url |
||
73 | * @return array |
||
74 | */ |
||
75 | public function followMethodCall($entityId, $entityName, $url) |
||
93 | |||
94 | /** |
||
95 | * Checks if bot is logged in |
||
96 | * |
||
97 | * @throws \LogicException if is not logged in |
||
98 | * @return bool |
||
99 | */ |
||
100 | public function checkLoggedIn() |
||
108 | |||
109 | /** |
||
110 | * Executes request to Pinterest API |
||
111 | * |
||
112 | * @param string $resourceUrl |
||
113 | * @param string $postString |
||
114 | * @return array |
||
115 | */ |
||
116 | public function exec($resourceUrl, $postString = "") |
||
128 | |||
129 | /** |
||
130 | * Adds necessary curl options for query |
||
131 | * |
||
132 | * @param string $postString POST query string |
||
133 | * @return array |
||
134 | */ |
||
135 | protected function makeHttpOptions($postString = "") |
||
150 | |||
151 | /** |
||
152 | * Clear token information |
||
153 | * |
||
154 | * @return mixed |
||
155 | */ |
||
156 | public function clearToken() |
||
160 | |||
161 | /** |
||
162 | * Mark api as logged |
||
163 | */ |
||
164 | public function setLoggedIn() |
||
171 | |||
172 | /** |
||
173 | * Get log status |
||
174 | * |
||
175 | * @return bool |
||
176 | */ |
||
177 | public function isLoggedIn() |
||
182 | |||
183 | /** |
||
184 | * @param array|object $data |
||
185 | * @param string|null $sourceUrl |
||
186 | * @param array $bookmarks |
||
187 | * @return array |
||
188 | */ |
||
189 | public static function createRequestData($data = [], $sourceUrl = '/', $bookmarks = []) |
||
206 | |||
207 | /** |
||
208 | * @return array |
||
209 | */ |
||
210 | protected static function createEmptyRequestData() |
||
214 | |||
215 | /** |
||
216 | * @return array |
||
217 | */ |
||
218 | protected function getDefaultHttpOptions() |
||
234 | |||
235 | /** |
||
236 | * @return array |
||
237 | */ |
||
238 | protected function getDefaultHttpHeaders() |
||
242 | |||
243 | /** |
||
244 | * @param $options |
||
245 | * @return mixed |
||
246 | */ |
||
247 | protected function addDefaultCsrfInfo($options) |
||
254 | } |
||
255 |