1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace seregazhuk\PinterestBot\Api\Providers; |
4
|
|
|
|
5
|
|
|
use seregazhuk\PinterestBot\Api\Request; |
6
|
|
|
use seregazhuk\PinterestBot\Helpers\Providers\Traits\Searchable; |
7
|
|
|
use seregazhuk\PinterestBot\Helpers\UrlHelper; |
8
|
|
|
|
9
|
|
|
class Pins extends Provider |
10
|
|
|
{ |
11
|
|
|
use Searchable; |
12
|
|
|
|
13
|
|
|
protected $loginRequired = [ |
14
|
|
|
'like', |
15
|
|
|
'unLike', |
16
|
|
|
'comment', |
17
|
|
|
'deleteComment', |
18
|
|
|
'create', |
19
|
|
|
'repin', |
20
|
|
|
'delete', |
21
|
|
|
]; |
22
|
|
|
|
23
|
|
|
/** |
24
|
|
|
* Likes pin with current ID. |
25
|
|
|
* |
26
|
|
|
* @param int $pinId |
27
|
|
|
* |
28
|
|
|
* @return bool |
29
|
|
|
*/ |
30
|
|
|
public function like($pinId) |
31
|
|
|
{ |
32
|
|
|
return $this->likePinMethodCall($pinId, UrlHelper::RESOURCE_LIKE_PIN); |
33
|
|
|
} |
34
|
|
|
|
35
|
|
|
/** |
36
|
|
|
* Removes your like from pin with current ID. |
37
|
|
|
* |
38
|
|
|
* @param int $pinId |
39
|
|
|
* |
40
|
|
|
* @return bool |
41
|
|
|
*/ |
42
|
|
|
public function unLike($pinId) |
43
|
|
|
{ |
44
|
|
|
return $this->likePinMethodCall($pinId, UrlHelper::RESOURCE_UNLIKE_PIN); |
45
|
|
|
} |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* Calls Pinterest API to like or unlike Pin by ID. |
49
|
|
|
* |
50
|
|
|
* @param int $pinId |
51
|
|
|
* @param string $resourceUrl |
52
|
|
|
* |
53
|
|
|
* @return bool |
54
|
|
|
*/ |
55
|
|
|
protected function likePinMethodCall($pinId, $resourceUrl) |
56
|
|
|
{ |
57
|
|
|
return $this->callPostRequest(['pin_id' => $pinId], $resourceUrl); |
58
|
|
|
} |
59
|
|
|
|
60
|
|
|
/** |
61
|
|
|
* Write a comment for a pin with current id. |
62
|
|
|
* |
63
|
|
|
* @param int $pinId |
64
|
|
|
* @param string $text Comment |
65
|
|
|
* |
66
|
|
|
* @return array|bool |
67
|
|
|
*/ |
68
|
|
|
public function comment($pinId, $text) |
69
|
|
|
{ |
70
|
|
|
$requestOptions = ['pin_id' => $pinId, 'test' => $text]; |
71
|
|
|
|
72
|
|
|
return $this->callPostRequest($requestOptions, UrlHelper::RESOURCE_COMMENT_PIN, true); |
73
|
|
|
} |
74
|
|
|
|
75
|
|
|
/** |
76
|
|
|
* Delete a comment for a pin with current id. |
77
|
|
|
* |
78
|
|
|
* @param int $pinId |
79
|
|
|
* @param int $commentId |
80
|
|
|
* |
81
|
|
|
* @return bool |
82
|
|
|
*/ |
83
|
|
|
public function deleteComment($pinId, $commentId) |
84
|
|
|
{ |
85
|
|
|
$requestOptions = ['pin_id' => $pinId, 'comment_id' => $commentId]; |
86
|
|
|
|
87
|
|
|
return $this->callPostRequest($requestOptions, UrlHelper::RESOURCE_COMMENT_DELETE_PIN); |
88
|
|
|
} |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Create a pin. Returns created pin ID. |
92
|
|
|
* |
93
|
|
|
* @param string $imageUrl |
94
|
|
|
* @param int $boardId |
95
|
|
|
* @param string $description |
96
|
|
|
* @param string $link |
97
|
|
|
* |
98
|
|
|
* @return bool|int |
99
|
|
|
*/ |
100
|
|
|
public function create($imageUrl, $boardId, $description = '', $link = '') |
101
|
|
|
{ |
102
|
|
|
$requestOptions = [ |
103
|
|
|
'method' => 'scraped', |
104
|
|
|
'description' => $description, |
105
|
|
|
'link' => empty($link) ? $imageUrl : $link, |
106
|
|
|
'image_url' => $imageUrl, |
107
|
|
|
'board_id' => $boardId, |
108
|
|
|
]; |
109
|
|
|
|
110
|
|
|
return $this->callPostRequest($requestOptions, UrlHelper::RESOURCE_CREATE_PIN, true); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* Update pin by ID. You can move pin to a new board by setting this board id. |
115
|
|
|
* |
116
|
|
|
* @param int $pindId |
117
|
|
|
* @param string $description |
118
|
|
|
* @param string $link |
119
|
|
|
* @param int|null $boardId |
120
|
|
|
* @return mixed |
121
|
|
|
*/ |
122
|
|
|
public function update($pindId, $description = '', $link = '', $boardId = null) |
123
|
|
|
{ |
124
|
|
|
$requestOptions = [ |
125
|
|
|
'id' => $pindId, |
126
|
|
|
'description' => $description, |
127
|
|
|
'link' => $link, |
128
|
|
|
'board_id' => $boardId, |
129
|
|
|
]; |
130
|
|
|
|
131
|
|
|
return $this->callPostRequest($requestOptions, UrlHelper::RESOURCE_UPDATE_PIN, true); |
132
|
|
|
} |
133
|
|
|
|
134
|
|
|
/** |
135
|
|
|
* Make a repin. |
136
|
|
|
* |
137
|
|
|
* @param int $repinId |
138
|
|
|
* @param int $boardId |
139
|
|
|
* @param string $description |
140
|
|
|
* |
141
|
|
|
* @return bool|int |
142
|
|
|
*/ |
143
|
|
|
public function repin($repinId, $boardId, $description = '') |
144
|
|
|
{ |
145
|
|
|
$requestOptions = [ |
146
|
|
|
'board_id' => $boardId, |
147
|
|
|
'description' => stripslashes($description), |
148
|
|
|
'link' => stripslashes($repinId), |
149
|
|
|
'is_video' => null, |
150
|
|
|
'pin_id' => $repinId, |
151
|
|
|
]; |
152
|
|
|
|
153
|
|
|
return $this->callPostRequest($requestOptions, UrlHelper::RESOURCE_REPIN, true); |
154
|
|
|
} |
155
|
|
|
|
156
|
|
|
/** |
157
|
|
|
* Delete a pin. |
158
|
|
|
* |
159
|
|
|
* @param int $pinId |
160
|
|
|
* |
161
|
|
|
* @return bool |
162
|
|
|
*/ |
163
|
|
|
public function delete($pinId) |
164
|
|
|
{ |
165
|
|
|
return $this->callPostRequest(['id' => $pinId], UrlHelper::RESOURCE_DELETE_PIN); |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* Get information of a pin by PinID. |
170
|
|
|
* |
171
|
|
|
* @param int $pinId |
172
|
|
|
* |
173
|
|
|
* @return array|bool |
174
|
|
|
*/ |
175
|
|
|
public function info($pinId) |
176
|
|
|
{ |
177
|
|
|
$requestOptions = [ |
178
|
|
|
'field_set_key' => 'detailed', |
179
|
|
|
'id' => $pinId, |
180
|
|
|
'pin_id' => $pinId, |
181
|
|
|
'allow_stale' => true, |
182
|
|
|
]; |
183
|
|
|
|
184
|
|
|
$data = ['options' => $requestOptions]; |
185
|
|
|
$url = UrlHelper::RESOURCE_PIN_INFO.'?'.Request::createQuery($data); |
186
|
|
|
$response = $this->request->exec($url); |
187
|
|
|
|
188
|
|
|
return $this->response->checkResponse($response); |
189
|
|
|
} |
190
|
|
|
|
191
|
|
|
/** |
192
|
|
|
* @return string |
193
|
|
|
*/ |
194
|
|
|
protected function getScope() |
195
|
|
|
{ |
196
|
|
|
return 'pins'; |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|