Completed
Pull Request — master (#100)
by Sergey
02:24
created

Boards::create()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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