1 | <?php |
||
15 | class Pins extends EntityProvider |
||
16 | { |
||
17 | use Searchable, CanBeDeleted, UploadsImages, SendsMessages; |
||
18 | |||
19 | /** |
||
20 | * @var array |
||
21 | */ |
||
22 | protected $loginRequiredFor = [ |
||
23 | 'like', |
||
24 | 'feed', |
||
25 | 'send', |
||
26 | 'copy', |
||
27 | 'move', |
||
28 | 'repin', |
||
29 | 'unLike', |
||
30 | 'create', |
||
31 | 'delete', |
||
32 | 'activity', |
||
33 | 'visualSimilar', |
||
34 | ]; |
||
35 | |||
36 | protected $searchScope = 'pins'; |
||
37 | protected $entityIdName = 'id'; |
||
38 | |||
39 | protected $messageEntityName = 'pin'; |
||
40 | |||
41 | protected $deleteUrl = UrlBuilder::RESOURCE_DELETE_PIN; |
||
42 | |||
43 | /** |
||
44 | * Likes pin with current ID. |
||
45 | * @param string $pinId |
||
46 | * @return bool |
||
47 | */ |
||
48 | public function like($pinId) |
||
52 | |||
53 | /** |
||
54 | * Removes your like from pin with current ID. |
||
55 | * @param string $pinId |
||
56 | * @return bool |
||
57 | */ |
||
58 | public function unLike($pinId) |
||
62 | |||
63 | /** |
||
64 | * Create a pin. Returns created pin info. |
||
65 | * |
||
66 | * @param string $imageUrl |
||
67 | * @param int $boardId |
||
68 | * @param string $description |
||
69 | * @param string $link |
||
70 | * @return array |
||
71 | */ |
||
72 | public function create($imageUrl, $boardId, $description = '', $link = '') |
||
73 | { |
||
74 | // Upload image if first argument is not url |
||
75 | if (!filter_var($imageUrl, FILTER_VALIDATE_URL)) { |
||
76 | $imageUrl = $this->upload($imageUrl); |
||
77 | } |
||
78 | |||
79 | $requestOptions = [ |
||
80 | 'method' => 'scraped', |
||
81 | 'description' => $description, |
||
82 | 'link' => empty($link) ? $imageUrl : $link, |
||
83 | 'image_url' => $imageUrl, |
||
84 | 'board_id' => $boardId, |
||
85 | ]; |
||
86 | |||
87 | $this->post($requestOptions, UrlBuilder::RESOURCE_CREATE_PIN); |
||
88 | |||
89 | return $this->response->getResponseData(); |
||
90 | } |
||
91 | |||
92 | /** |
||
93 | * Edit pin by ID. You can move pin to a new board by setting this board id. |
||
94 | * |
||
95 | * @param int $pindId |
||
96 | * @param string $description |
||
97 | * @param string $link |
||
98 | * @param int|null $boardId |
||
99 | * @return bool |
||
100 | */ |
||
101 | public function edit($pindId, $description = '', $link = '', $boardId = null) |
||
112 | |||
113 | /** |
||
114 | * Moves pin to a new board |
||
115 | * |
||
116 | * @param int $pinId |
||
117 | * @param int $boardId |
||
118 | * @return bool |
||
119 | */ |
||
120 | public function moveToBoard($pinId, $boardId) |
||
124 | |||
125 | /** |
||
126 | * Make a repin. |
||
127 | * |
||
128 | * @param int $repinId |
||
129 | * @param int $boardId |
||
130 | * @param string $description |
||
131 | * @return array |
||
132 | */ |
||
133 | public function repin($repinId, $boardId, $description = '') |
||
134 | { |
||
135 | $requestOptions = [ |
||
136 | 'board_id' => $boardId, |
||
137 | 'description' => stripslashes($description), |
||
138 | 'link' => stripslashes($repinId), |
||
139 | 'is_video' => null, |
||
140 | 'pin_id' => $repinId, |
||
141 | ]; |
||
142 | |||
143 | $this->post($requestOptions, UrlBuilder::RESOURCE_REPIN); |
||
144 | |||
145 | return $this->response->getResponseData(); |
||
146 | } |
||
147 | |||
148 | /** |
||
149 | * Get information of a pin by PinID. |
||
150 | * |
||
151 | * @param string $pinId |
||
152 | * @return array|bool |
||
153 | */ |
||
154 | public function info($pinId) |
||
163 | |||
164 | /** |
||
165 | * Get pins from a specific url. For example: https://pinterest.com/source/flickr.com/ will |
||
166 | * return recent Pins from flickr.com |
||
167 | * |
||
168 | * @param string $source |
||
169 | * @param int $limit |
||
170 | * @return Pagination |
||
171 | */ |
||
172 | public function fromSource($source, $limit = Pagination::DEFAULT_LIMIT) |
||
178 | |||
179 | /** |
||
180 | * Get the latest pin activity with pagination. |
||
181 | * |
||
182 | * @param string $pinId |
||
183 | * @param int $limit |
||
184 | * @return Pagination |
||
185 | */ |
||
186 | public function activity($pinId, $limit = Pagination::DEFAULT_LIMIT) |
||
190 | |||
191 | /** |
||
192 | * Get the pinners who have tied this pin |
||
193 | * |
||
194 | * @param string $pinId |
||
195 | * @param int $limit |
||
196 | * @return Pagination |
||
197 | */ |
||
198 | public function tried($pinId, $limit = Pagination::DEFAULT_LIMIT) |
||
207 | |||
208 | /** |
||
209 | * @param string $pinId |
||
210 | * @param array $additionalData |
||
211 | * @param int $limit |
||
212 | * @return Pagination |
||
213 | */ |
||
214 | protected function getAggregatedActivity($pinId, $additionalData = [], $limit) |
||
224 | |||
225 | /** |
||
226 | * Get pins from user's feed |
||
227 | * |
||
228 | * @param int $limit |
||
229 | * @return Pagination |
||
230 | */ |
||
231 | public function feed($limit = Pagination::DEFAULT_LIMIT) |
||
235 | |||
236 | /** |
||
237 | * @param string $pinId |
||
238 | * @param int $limit |
||
239 | * @return Pagination |
||
240 | */ |
||
241 | public function related($pinId, $limit = Pagination::DEFAULT_LIMIT) |
||
250 | |||
251 | /** |
||
252 | * Copy pins to board |
||
253 | * |
||
254 | * @param array|string $pinIds |
||
255 | * @param int $boardId |
||
256 | * @return bool|Response |
||
257 | */ |
||
258 | public function copy($pinIds, $boardId) |
||
262 | |||
263 | /** |
||
264 | * Delete pins from board. |
||
265 | * |
||
266 | * @param string|array $pinIds |
||
267 | * @param int $boardId |
||
268 | * @return bool |
||
269 | */ |
||
270 | public function deleteFromBoard($pinIds, $boardId) |
||
274 | |||
275 | /** |
||
276 | * Move pins to board |
||
277 | * |
||
278 | * @param string|array $pinIds |
||
279 | * @param int $boardId |
||
280 | * @return bool|Response |
||
281 | */ |
||
282 | public function move($pinIds, $boardId) |
||
286 | |||
287 | /** |
||
288 | * @param string $pinId |
||
289 | * @param array $crop |
||
290 | * @return array|bool |
||
291 | */ |
||
292 | public function visualSimilar($pinId, array $crop = []) |
||
309 | |||
310 | /** |
||
311 | * Saves the pin original image to the specified path. On success |
||
312 | * returns full path to saved image. Otherwise returns false. |
||
313 | * |
||
314 | * @param string $pinId |
||
315 | * @param string $path |
||
316 | * @return false|string |
||
317 | */ |
||
318 | public function saveOriginalImage($pinId, $path) |
||
330 | |||
331 | /** |
||
332 | * @param string $query |
||
333 | * @param int $limit |
||
334 | * @return Pagination |
||
335 | */ |
||
336 | public function searchInMyPins($query, $limit = Pagination::DEFAULT_LIMIT) |
||
342 | |||
343 | /** |
||
344 | * Returns trending pins from http://pinterest.com/discover page. Uses topic id, that can be received |
||
345 | * from $bot->topics->explore() method. |
||
346 | * |
||
347 | * @param string $topicId |
||
348 | * @param int $limit |
||
349 | * @return Pagination |
||
350 | */ |
||
351 | public function explore($topicId, $limit = Pagination::DEFAULT_LIMIT) |
||
362 | |||
363 | /** |
||
364 | * Calls Pinterest API to like or unlike Pin by ID. |
||
365 | * |
||
366 | * @param string $pinId |
||
367 | * @param string $resourceUrl |
||
368 | * @return bool |
||
369 | */ |
||
370 | protected function likePinMethodCall($pinId, $resourceUrl) |
||
374 | |||
375 | /** |
||
376 | * @param string $pinId |
||
377 | * @return int|null |
||
378 | */ |
||
379 | protected function getAggregatedPinId($pinId) |
||
387 | |||
388 | /** |
||
389 | * @param mixed $params |
||
390 | * @return array |
||
391 | */ |
||
392 | protected function getFeedRequestData($params = []) |
||
396 | |||
397 | /** |
||
398 | * @param string|array $pinIds |
||
399 | * @param int $boardId |
||
400 | * @param string $editUrl |
||
401 | * @return bool |
||
402 | */ |
||
403 | protected function bulkEdit($pinIds, $boardId, $editUrl) |
||
414 | } |
||
415 |