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 | 'analytics', |
||
34 | 'visualSimilar', |
||
35 | ]; |
||
36 | |||
37 | protected $searchScope = 'pins'; |
||
38 | protected $entityIdName = 'id'; |
||
39 | |||
40 | protected $messageEntityName = 'pin'; |
||
41 | |||
42 | protected $deleteUrl = UrlBuilder::RESOURCE_DELETE_PIN; |
||
43 | |||
44 | /** |
||
45 | * Likes pin with current ID. |
||
46 | * @param string $pinId |
||
47 | * @return bool |
||
48 | */ |
||
49 | public function like($pinId) |
||
50 | { |
||
51 | return $this->likePinMethodCall($pinId, UrlBuilder::RESOURCE_LIKE_PIN); |
||
52 | } |
||
53 | |||
54 | /** |
||
55 | * Removes your like from pin with current ID. |
||
56 | * @param string $pinId |
||
57 | * @return bool |
||
58 | */ |
||
59 | public function unLike($pinId) |
||
60 | { |
||
61 | return $this->likePinMethodCall($pinId, UrlBuilder::RESOURCE_UNLIKE_PIN); |
||
62 | } |
||
63 | |||
64 | /** |
||
65 | * Create a pin. Returns created pin info. |
||
66 | * |
||
67 | * @param string $imageUrl |
||
68 | * @param int $boardId |
||
69 | * @param string $description |
||
70 | * @param string $link |
||
71 | * @return array |
||
72 | */ |
||
73 | public function create($imageUrl, $boardId, $description = '', $link = '') |
||
74 | { |
||
75 | // Upload image if first argument is not url |
||
76 | if (!filter_var($imageUrl, FILTER_VALIDATE_URL)) { |
||
77 | $imageUrl = $this->upload($imageUrl); |
||
78 | } |
||
79 | |||
80 | $requestOptions = [ |
||
81 | 'method' => 'scraped', |
||
82 | 'description' => $description, |
||
83 | 'link' => empty($link) ? $imageUrl : $link, |
||
84 | 'image_url' => $imageUrl, |
||
85 | 'board_id' => $boardId, |
||
86 | ]; |
||
87 | |||
88 | $this->post($requestOptions, UrlBuilder::RESOURCE_CREATE_PIN); |
||
89 | |||
90 | return $this->response->getResponseData(); |
||
91 | } |
||
92 | |||
93 | /** |
||
94 | * Edit pin by ID. You can move pin to a new board by setting this board id. |
||
95 | * |
||
96 | * @param int $pindId |
||
97 | * @param string $description |
||
98 | * @param string $link |
||
99 | * @param int|null $boardId |
||
100 | * @return bool |
||
101 | */ |
||
102 | public function edit($pindId, $description = '', $link = '', $boardId = null) |
||
103 | { |
||
104 | $requestOptions = [ |
||
105 | 'id' => $pindId, |
||
106 | 'description' => $description, |
||
107 | 'link' => $link, |
||
108 | 'board_id' => $boardId, |
||
109 | ]; |
||
110 | |||
111 | return $this->post($requestOptions, UrlBuilder::RESOURCE_UPDATE_PIN); |
||
112 | } |
||
113 | |||
114 | /** |
||
115 | * Moves pin to a new board |
||
116 | * |
||
117 | * @param int $pinId |
||
118 | * @param int $boardId |
||
119 | * @return bool |
||
120 | */ |
||
121 | public function moveToBoard($pinId, $boardId) |
||
122 | { |
||
123 | return $this->edit($pinId, '', '', $boardId); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Make a repin. |
||
128 | * |
||
129 | * @param int $repinId |
||
130 | * @param int $boardId |
||
131 | * @param string $description |
||
132 | * @return array |
||
133 | */ |
||
134 | public function repin($repinId, $boardId, $description = '') |
||
135 | { |
||
136 | $requestOptions = [ |
||
137 | 'board_id' => $boardId, |
||
138 | 'description' => stripslashes($description), |
||
139 | 'link' => stripslashes($repinId), |
||
140 | 'is_video' => null, |
||
141 | 'pin_id' => $repinId, |
||
142 | ]; |
||
143 | |||
144 | $this->post($requestOptions, UrlBuilder::RESOURCE_REPIN); |
||
145 | |||
146 | return $this->response->getResponseData(); |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * Get information of a pin by PinID. |
||
151 | * |
||
152 | * @param string $pinId |
||
153 | * @return array|bool |
||
154 | */ |
||
155 | public function info($pinId) |
||
164 | |||
165 | /** |
||
166 | * Get pins from a specific url. For example: https://pinterest.com/source/flickr.com/ will |
||
167 | * return recent Pins from flickr.com |
||
168 | * |
||
169 | * @param string $source |
||
170 | * @param int $limit |
||
171 | * @return Pagination |
||
172 | */ |
||
173 | public function fromSource($source, $limit = Pagination::DEFAULT_LIMIT) |
||
179 | |||
180 | /** |
||
181 | * Get the latest pin activity with pagination. |
||
182 | * |
||
183 | * @param string $pinId |
||
184 | * @param int $limit |
||
185 | * @return Pagination |
||
186 | */ |
||
187 | public function activity($pinId, $limit = Pagination::DEFAULT_LIMIT) |
||
191 | |||
192 | /** |
||
193 | * Get the pinners who have tied this pin |
||
194 | * |
||
195 | * @param string $pinId |
||
196 | * @param int $limit |
||
197 | * @return Pagination |
||
198 | */ |
||
199 | public function tried($pinId, $limit = Pagination::DEFAULT_LIMIT) |
||
208 | |||
209 | /** |
||
210 | * @param string $pinId |
||
211 | * @param array $additionalData |
||
212 | * @param int $limit |
||
213 | * @return Pagination |
||
214 | */ |
||
215 | protected function getAggregatedActivity($pinId, $additionalData = [], $limit) |
||
225 | |||
226 | /** |
||
227 | * Get pins from user's feed |
||
228 | * |
||
229 | * @param int $limit |
||
230 | * @return Pagination |
||
231 | */ |
||
232 | public function feed($limit = Pagination::DEFAULT_LIMIT) |
||
236 | |||
237 | /** |
||
238 | * @param string $pinId |
||
239 | * @param int $limit |
||
240 | * @return Pagination |
||
241 | */ |
||
242 | public function related($pinId, $limit = Pagination::DEFAULT_LIMIT) |
||
251 | |||
252 | /** |
||
253 | * Copy pins to board |
||
254 | * |
||
255 | * @param array|string $pinIds |
||
256 | * @param int $boardId |
||
257 | * @return bool|Response |
||
258 | */ |
||
259 | public function copy($pinIds, $boardId) |
||
263 | |||
264 | /** |
||
265 | * Delete pins from board. |
||
266 | * |
||
267 | * @param string|array $pinIds |
||
268 | * @param int $boardId |
||
269 | * @return bool |
||
270 | */ |
||
271 | public function deleteFromBoard($pinIds, $boardId) |
||
275 | |||
276 | /** |
||
277 | * Move pins to board |
||
278 | * |
||
279 | * @param string|array $pinIds |
||
280 | * @param int $boardId |
||
281 | * @return bool|Response |
||
282 | */ |
||
283 | public function move($pinIds, $boardId) |
||
287 | |||
288 | /** |
||
289 | * @param string $pinId |
||
290 | * @param array $crop |
||
291 | * @return array|bool |
||
292 | */ |
||
293 | public function visualSimilar($pinId, array $crop = []) |
||
310 | |||
311 | /** |
||
312 | * Saves the pin original image to the specified path. On success |
||
313 | * returns full path to saved image. Otherwise returns false. |
||
314 | * |
||
315 | * @param string $pinId |
||
316 | * @param string $path |
||
317 | * @return false|string |
||
318 | */ |
||
319 | public function saveOriginalImage($pinId, $path) |
||
331 | |||
332 | /** |
||
333 | * @param string $query |
||
334 | * @param int $limit |
||
335 | * @return Pagination |
||
336 | */ |
||
337 | public function searchInMyPins($query, $limit = Pagination::DEFAULT_LIMIT) |
||
343 | |||
344 | /** |
||
345 | * Returns trending pins from http://pinterest.com/discover page. Uses topic id, that can be received |
||
346 | * from $bot->topics->explore() method. |
||
347 | * |
||
348 | * @param string $topicId |
||
349 | * @param int $limit |
||
350 | * @return Pagination |
||
351 | */ |
||
352 | public function explore($topicId, $limit = Pagination::DEFAULT_LIMIT) |
||
363 | |||
364 | /** |
||
365 | * Get pin analytics, like numbers of clicks, views and repins |
||
366 | * @param $pinId |
||
367 | * @return array|bool|Response |
||
368 | */ |
||
369 | public function analytics($pinId) |
||
373 | |||
374 | /** |
||
375 | * Calls Pinterest API to like or unlike Pin by ID. |
||
376 | * |
||
377 | * @param string $pinId |
||
378 | * @param string $resourceUrl |
||
379 | * @return bool |
||
380 | */ |
||
381 | protected function likePinMethodCall($pinId, $resourceUrl) |
||
385 | |||
386 | /** |
||
387 | * @param string $pinId |
||
388 | * @return int|null |
||
389 | */ |
||
390 | protected function getAggregatedPinId($pinId) |
||
398 | |||
399 | /** |
||
400 | * @param mixed $params |
||
401 | * @return array |
||
402 | */ |
||
403 | protected function getFeedRequestData($params = []) |
||
407 | |||
408 | /** |
||
409 | * @param string|array $pinIds |
||
410 | * @param int $boardId |
||
411 | * @param string $editUrl |
||
412 | * @return bool |
||
413 | */ |
||
414 | protected function bulkEdit($pinIds, $boardId, $editUrl) |
||
425 | } |
||
426 |