1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace seregazhuk\PinterestBot\Api\Providers; |
4
|
|
|
|
5
|
|
|
use seregazhuk\PinterestBot\Helpers\Pagination; |
6
|
|
|
use seregazhuk\PinterestBot\Helpers\UrlBuilder; |
7
|
|
|
use seregazhuk\PinterestBot\Api\Traits\Searchable; |
8
|
|
|
use seregazhuk\PinterestBot\Api\Traits\CanBeDeleted; |
9
|
|
|
use seregazhuk\PinterestBot\Api\Traits\BoardsInvites; |
10
|
|
|
use seregazhuk\PinterestBot\Api\Traits\SendsMessages; |
11
|
|
|
use seregazhuk\PinterestBot\Api\Traits\ResolvesCurrentUsername; |
12
|
|
|
use seregazhuk\PinterestBot\Api\Providers\Core\FollowableProvider; |
13
|
|
|
|
14
|
|
|
class Boards extends FollowableProvider |
15
|
|
|
{ |
16
|
|
|
use CanBeDeleted, Searchable, SendsMessages, ResolvesCurrentUsername, BoardsInvites; |
17
|
|
|
|
18
|
|
|
const BOARD_PRIVACY_PUBLIC = 'public'; |
19
|
|
|
const BOARD_PRIVACY_PRIVATE = 'secret'; |
20
|
|
|
|
21
|
|
|
/** |
22
|
|
|
* @var array |
23
|
|
|
*/ |
24
|
|
|
protected $loginRequiredFor = [ |
25
|
|
|
'my', |
26
|
|
|
'send', |
27
|
|
|
'delete', |
28
|
|
|
'create', |
29
|
|
|
'follow', |
30
|
|
|
'invites', |
31
|
|
|
'unFollow', |
32
|
|
|
'sendInvite', |
33
|
|
|
'sendInviteByEmail', |
34
|
|
|
'sendInviteByUserId', |
35
|
|
|
'deleteInvite', |
36
|
|
|
'acceptInvite', |
37
|
|
|
]; |
38
|
|
|
|
39
|
|
|
protected $searchScope = 'boards'; |
40
|
|
|
protected $entityIdName = 'board_id'; |
41
|
|
|
protected $followersFor = 'board_id'; |
42
|
|
|
|
43
|
|
|
protected $followUrl = UrlBuilder::RESOURCE_FOLLOW_BOARD; |
44
|
|
|
protected $unFollowUrl = UrlBuilder::RESOURCE_UNFOLLOW_BOARD; |
45
|
|
|
protected $deleteUrl = UrlBuilder::RESOURCE_DELETE_BOARD; |
46
|
|
|
protected $followersUrl = UrlBuilder::RESOURCE_BOARD_FOLLOWERS; |
47
|
|
|
|
48
|
|
|
protected $messageEntityName = 'board'; |
49
|
|
|
|
50
|
|
|
/** |
51
|
|
|
* Get boards for user by username. |
52
|
|
|
* |
53
|
|
|
* @param string $username |
54
|
|
|
* |
55
|
|
|
* @return array |
56
|
|
|
*/ |
57
|
|
|
public function forUser($username) |
58
|
|
|
{ |
59
|
|
|
$options = [ |
60
|
|
|
'username' => $username, |
61
|
|
|
'field_set_key' => 'detailed', |
62
|
|
|
]; |
63
|
|
|
|
64
|
|
|
$result = $this->get($options, UrlBuilder::RESOURCE_GET_BOARDS); |
65
|
|
|
|
66
|
|
|
return $result ? : []; |
67
|
|
|
} |
68
|
|
|
|
69
|
|
|
/** |
70
|
|
|
* Get boards for current logged in user. |
71
|
|
|
* |
72
|
|
|
* @return array |
73
|
|
|
*/ |
74
|
|
|
public function forMe() |
75
|
|
|
{ |
76
|
|
|
$currentUserName = $this->resolveCurrentUsername(); |
77
|
|
|
|
78
|
|
|
if (!$currentUserName) return []; |
79
|
|
|
|
80
|
|
|
return $this->forUser($currentUserName); |
81
|
|
|
} |
82
|
|
|
|
83
|
|
|
/** |
84
|
|
|
* Get info about user's board. |
85
|
|
|
* |
86
|
|
|
* @param string $username |
87
|
|
|
* @param string $board |
88
|
|
|
* |
89
|
|
|
* @return array|bool |
90
|
|
|
*/ |
91
|
|
|
public function info($username, $board) |
92
|
|
|
{ |
93
|
|
|
$requestOptions = [ |
94
|
|
|
'slug' => $this->formatBoardName($board), |
95
|
|
|
'username' => $username, |
96
|
|
|
'field_set_key' => 'detailed', |
97
|
|
|
]; |
98
|
|
|
|
99
|
|
|
return $this->get($requestOptions, UrlBuilder::RESOURCE_GET_BOARD); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param string $board |
104
|
|
|
* @return string |
105
|
|
|
*/ |
106
|
|
|
protected function formatBoardName($board) |
107
|
|
|
{ |
108
|
|
|
return strtolower(str_replace(' ', '-', $board)); |
109
|
|
|
} |
110
|
|
|
|
111
|
|
|
/** |
112
|
|
|
* Get pins from board by boardId. |
113
|
|
|
* |
114
|
|
|
* @param int $boardId |
115
|
|
|
* @param int $limit |
116
|
|
|
* |
117
|
|
|
* @return Pagination |
118
|
|
|
*/ |
119
|
|
|
public function pins($boardId, $limit = Pagination::DEFAULT_LIMIT) |
120
|
|
|
{ |
121
|
|
|
return $this->paginate( |
122
|
|
|
['board_id' => $boardId], |
123
|
|
|
UrlBuilder::RESOURCE_GET_BOARD_FEED, |
124
|
|
|
$limit |
125
|
|
|
); |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* Update board info. Gets boardId and an associative array as params. Available keys of the array are: |
130
|
|
|
* 'name', 'category', 'description', 'privacy'. |
131
|
|
|
* |
132
|
|
|
* - 'privacy' can be 'public' or 'secret'. 'public' by default. |
133
|
|
|
* - 'category' is 'other' by default. |
134
|
|
|
* |
135
|
|
|
* @param $boardId |
136
|
|
|
* @param $attributes |
137
|
|
|
* @return mixed |
138
|
|
|
*/ |
139
|
|
|
public function update($boardId, $attributes) |
140
|
|
|
{ |
141
|
|
|
$requestOptions = array_merge( |
142
|
|
|
[ |
143
|
|
|
'board_id' => $boardId, |
144
|
|
|
'category' => 'other', |
145
|
|
|
], $attributes |
146
|
|
|
); |
147
|
|
|
|
148
|
|
|
return $this->post($requestOptions, UrlBuilder::RESOURCE_UPDATE_BOARD); |
149
|
|
|
} |
150
|
|
|
|
151
|
|
|
/** |
152
|
|
|
* Create a new board. |
153
|
|
|
* |
154
|
|
|
* @param string $name |
155
|
|
|
* @param string $description |
156
|
|
|
* @param string $privacy Can be 'public' or 'secret'. 'public' by default. |
157
|
|
|
* |
158
|
|
|
* @return bool |
159
|
|
|
*/ |
160
|
|
|
public function create($name, $description, $privacy = self::BOARD_PRIVACY_PUBLIC) |
161
|
|
|
{ |
162
|
|
|
$requestOptions = [ |
163
|
|
|
'name' => $name, |
164
|
|
|
'description' => $description, |
165
|
|
|
'privacy' => $privacy, |
166
|
|
|
]; |
167
|
|
|
|
168
|
|
|
return $this->post($requestOptions, UrlBuilder::RESOURCE_CREATE_BOARD); |
169
|
|
|
} |
170
|
|
|
|
171
|
|
|
/** |
172
|
|
|
* Create a new board. |
173
|
|
|
* |
174
|
|
|
* @codeCoverageIgnore |
175
|
|
|
* @param string $name |
176
|
|
|
* @param string $description |
177
|
|
|
* |
178
|
|
|
* @return bool |
179
|
|
|
*/ |
180
|
|
|
public function createPrivate($name, $description) |
181
|
|
|
{ |
182
|
|
|
return $this->create($name, $description, self::BOARD_PRIVACY_PRIVATE); |
183
|
|
|
} |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Returns title suggestions for pin. |
187
|
|
|
* |
188
|
|
|
* @param string $pinId |
189
|
|
|
* @return array|bool |
190
|
|
|
*/ |
191
|
|
|
public function titleSuggestionsFor($pinId) |
192
|
|
|
{ |
193
|
|
|
return $this->get(['pin_id' => $pinId], UrlBuilder::RESOURCE_TITLE_SUGGESTIONS); |
194
|
|
|
} |
195
|
|
|
|
196
|
|
|
|
197
|
|
|
} |
198
|
|
|
|