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

Boards::delete()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 5
Bugs 2 Features 1
Metric Value
c 5
b 2
f 1
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 1
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
     * Create a new board.
100
     *
101
     * @param string $name
102
     * @param string $description
103
     * @param string $privacy     Can be 'public' or 'secret'. 'public' by default.
104
     *
105
     * @return bool
106
     */
107
    public function create($name, $description, $privacy = 'public')
108
    {
109
        $requestOptions = [
110
            'name'        => $name,
111
            'description' => $description,
112
            'privacy'     => $privacy,
113
        ];
114
115
        return $this->execPostRequest($requestOptions, UrlHelper::RESOURCE_CREATE_BOARD);
116
    }
117
118
    /**
119
     * Get board followers.
120
     *
121
     * @param $boardId
122
     * @param int $batchesLimit
123
     *
124
     * @return Iterator
125
     */
126
    public function followers($boardId, $batchesLimit = 0)
127
    {
128
        return $this->getFollowData(
129
            ['board_id' => $boardId], UrlHelper::RESOURCE_BOARD_FOLLOWERS, '', $batchesLimit
130
        );
131
    }
132
133
    /**
134
     * Search scope.
135
     *
136
     * @return string
137
     */
138
    protected function getScope()
139
    {
140
        return 'boards';
141
    }
142
143
    protected function getEntityIdName()
144
    {
145
        return 'board_id';
146
    }
147
148
    /**
149
     * Follow resource.
150
     *
151
     * @return string
152
     */
153
    protected function getFollowUrl()
154
    {
155
        return UrlHelper::RESOURCE_FOLLOW_BOARD;
156
    }
157
158
    /**
159
     * UnFollow resource.
160
     *
161
     * @return string
162
     */
163
    protected function getUnfFollowUrl()
164
    {
165
        return UrlHelper::RESOURCE_UNFOLLOW_BOARD;
166
    }
167
}
168