Completed
Push — master ( cc9e5c...67ffd6 )
by Sergey
13:28 queued 10:12
created

Boards::followers()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
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\Providers\Traits\CanBeDeleted;
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 CanBeDeleted, Searchable, Followable, HasFollowers;
16
17
    protected $loginRequiredFor = [
18
        'delete',
19
        'create',
20
        'follow',
21
        'unFollow',
22
    ];
23
24
    protected $searchScope  = 'boards';
25
    protected $entityIdName = 'board_id';
26
    protected $followersFor = 'board_id';
27
28
    protected $followUrl    = UrlHelper::RESOURCE_FOLLOW_BOARD;
29
    protected $unFollowUrl  = UrlHelper::RESOURCE_UNFOLLOW_BOARD;
30
    protected $deleteUrl    = UrlHelper::RESOURCE_DELETE_BOARD;
31
    protected $followersUrl = UrlHelper::RESOURCE_BOARD_FOLLOWERS;
32
    
33
    /**
34
     * Get boards for user by username.
35
     *
36
     * @param string $username
37
     *
38
     * @return array|bool
39
     */
40
    public function forUser($username)
41
    {
42
        return $this->execGetRequest(['username' => $username], UrlHelper::RESOURCE_GET_BOARDS);
43
    }
44
45
    /**
46
     * Get info about user's board.
47
     *
48
     * @param string $username
49
     * @param string $board
50
     *
51
     * @return array|bool
52
     */
53
    public function info($username, $board)
54
    {
55
        $requestOptions = [
56
            'username'      => $username,
57
            'slug'          => $board,
58
            'field_set_key' => 'detailed',
59
        ];
60
61
        return $this->execGetRequest(
62
            $requestOptions, UrlHelper::RESOURCE_GET_BOARDS
63
        );
64
    }
65
66
    /**
67
     * Get pins from board by boardId.
68
     *
69
     * @param int $boardId
70
     * @param int $limit
71
     *
72
     * @return Iterator
73
     */
74
    public function pins($boardId, $limit = 0)
75
    {
76
        return (new Pagination($this))->paginateOver(
77
            'getPinsFromBoard', ['boardId' => $boardId], $limit
78
        );
79
    }
80
81
    /**
82
     * @param int   $boardId
83
     * @param array $bookmarks
84
     *
85
     * @return array|bool
86
     */
87
    public function getPinsFromBoard($boardId, $bookmarks = [])
88
    {
89
        return $this->execGetRequestWithPagination(
90
            ['board_id' => $boardId], UrlHelper::RESOURCE_GET_BOARD_FEED, $bookmarks
91
        );
92
    }
93
94
    /**
95
     * Update board info. Gets boardId and an associative array as params. Available keys of the array are:
96
     * 'category', 'description', 'privacy'.
97
     *
98
     * - 'privacy' can be 'public' or 'secret'. 'public' by default.
99
     * - 'category' is 'other' by default.
100
     *
101
     * @param $boardId
102
     * @param $attributes
103
     * @return mixed
104
     */
105
    public function update($boardId, $attributes)
106
    {
107
        $requestOptions = array_merge(
108
            [
109
                'board_id' => $boardId,
110
                'category' => 'other',
111
            ], $attributes
112
        );
113
114
        return $this->execPostRequest($requestOptions, UrlHelper::RESOURCE_UPDATE_BOARD);
115
    }
116
117
    /**
118
     * Create a new board.
119
     *
120
     * @param string $name
121
     * @param string $description
122
     * @param string $privacy     Can be 'public' or 'secret'. 'public' by default.
123
     *
124
     * @return bool
125
     */
126
    public function create($name, $description, $privacy = 'public')
127
    {
128
        $requestOptions = [
129
            'name'        => $name,
130
            'description' => $description,
131
            'privacy'     => $privacy,
132
        ];
133
134
        return $this->execPostRequest($requestOptions, UrlHelper::RESOURCE_CREATE_BOARD);
135
    }
136
}
137