Completed
Push — master ( a6f1c6...fad4ca )
by Sergey
59s
created

Boards::getPinsFromBoard()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 4
Bugs 2 Features 0
Metric Value
c 4
b 2
f 0
dl 0
loc 6
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api\Providers;
4
5
use Iterator;
6
use seregazhuk\PinterestBot\Helpers\UrlHelper;
7
use seregazhuk\PinterestBot\Helpers\Pagination;
8
use seregazhuk\PinterestBot\Helpers\Providers\Traits\Searchable;
9
use seregazhuk\PinterestBot\Helpers\Providers\Traits\Followable;
10
use seregazhuk\PinterestBot\Helpers\Providers\Traits\HasFollowers;
11
12
class Boards extends Provider
13
{
14
    use Searchable, Followable, HasFollowers;
15
16
    protected $loginRequired = [
17
        'delete',
18
        'create',
19
        'follow',
20
        'unFollow',
21
    ];
22
23
    /**
24
     * Get boards for user by username.
25
     *
26
     * @param string $username
27
     *
28
     * @return array|bool
29
     */
30
    public function forUser($username)
31
    {
32
        return $this->execGetRequest(['username' => $username], UrlHelper::RESOURCE_GET_BOARDS);
33
    }
34
35
    /**
36
     * Get info about user's board.
37
     *
38
     * @param string $username
39
     * @param string $board
40
     *
41
     * @return array|bool
42
     */
43
    public function info($username, $board)
44
    {
45
        $requestOptions = [
46
            'username'      => $username,
47
            'slug'          => $board,
48
            'field_set_key' => 'detailed',
49
        ];
50
51
        return $this->execGetRequest(
52
            $requestOptions, UrlHelper::RESOURCE_GET_BOARDS
53
        );
54
    }
55
56
    /**
57
     * Get pins from board by boardId.
58
     *
59
     * @param int $boardId
60
     * @param int $batchesLimit
61
     *
62
     * @return Iterator
63
     */
64
    public function pins($boardId, $batchesLimit = 0)
65
    {
66
        return (new Pagination($this))->run(
67
            'getPinsFromBoard',
68
            ['boardId' => $boardId],
69
            $batchesLimit
70
        );
71
    }
72
73
    /**
74
     * @param int   $boardId
75
     * @param array $bookmarks
76
     *
77
     * @return array|bool
78
     */
79
    public function getPinsFromBoard($boardId, $bookmarks = [])
80
    {
81
        return $this->execGetRequest(
82
            ['board_id' => $boardId], UrlHelper::RESOURCE_GET_BOARD_FEED, true, $bookmarks
83
        );
84
    }
85
86
    /**
87
     * Delete your board by ID.
88
     *
89
     * @param int $boardId
90
     *
91
     * @return bool
92
     */
93
    public function delete($boardId)
94
    {
95
        return $this->execPostRequest(['board_id' => $boardId], UrlHelper::RESOURCE_DELETE_BOARD);
96
    }
97
98
    /**
99
     * Update board info. Gets boardId and an associative array as params. Available keys of the array are:
100
     * 'category', 'description', 'privacy'.
101
     *
102
     * - 'privacy' can be 'public' or 'secret'. 'public' by default.
103
     * - 'category' is 'other' by default.
104
     *
105
     * @param $boardId
106
     * @param $attributes
107
     * @return mixed
108
     */
109
    public function update($boardId, $attributes)
110
    {
111
        $requestOptions = array_merge(
112
            [
113
                'board_id' => $boardId,
114
                'category' => 'other',
115
            ], $attributes
116
        );
117
118
        return $this->execPostRequest($requestOptions, UrlHelper::RESOURCE_UPDATE_BOARD);
119
    }
120
121
    /**
122
     * Create a new board.
123
     *
124
     * @param string $name
125
     * @param string $description
126
     * @param string $privacy     Can be 'public' or 'secret'. 'public' by default.
127
     *
128
     * @return bool
129
     */
130
    public function create($name, $description, $privacy = 'public')
131
    {
132
        $requestOptions = [
133
            'name'        => $name,
134
            'description' => $description,
135
            'privacy'     => $privacy,
136
        ];
137
138
        return $this->execPostRequest($requestOptions, UrlHelper::RESOURCE_CREATE_BOARD);
139
    }
140
141
    /**
142
     * Get board followers.
143
     *
144
     * @param $boardId
145
     * @param int $batchesLimit
146
     *
147
     * @return Iterator
148
     */
149
    public function followers($boardId, $batchesLimit = 0)
150
    {
151
        return $this->getFollowData(
152
            ['board_id' => $boardId], UrlHelper::RESOURCE_BOARD_FOLLOWERS, $batchesLimit
153
        );
154
    }
155
156
    /**
157
     * Search scope.
158
     *
159
     * @return string
160
     */
161
    protected function getScope()
162
    {
163
        return 'boards';
164
    }
165
166
    protected function getEntityIdName()
167
    {
168
        return 'board_id';
169
    }
170
171
    /**
172
     * Follow resource.
173
     *
174
     * @return string
175
     */
176
    protected function getFollowUrl()
177
    {
178
        return UrlHelper::RESOURCE_FOLLOW_BOARD;
179
    }
180
181
    /**
182
     * UnFollow resource.
183
     *
184
     * @return string
185
     */
186
    protected function getUnfFollowUrl()
187
    {
188
        return UrlHelper::RESOURCE_UNFOLLOW_BOARD;
189
    }
190
}
191