Completed
Pull Request — master (#209)
by Sergey
03:41
created

Boards::titleSuggestionsFor()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api\Providers;
4
5
use Generator;
6
use seregazhuk\PinterestBot\Helpers\UrlBuilder;
7
use seregazhuk\PinterestBot\Api\Traits\Searchable;
8
use seregazhuk\PinterestBot\Api\Traits\Followable;
9
use seregazhuk\PinterestBot\Api\Traits\CanBeDeleted;
10
use seregazhuk\PinterestBot\Api\Contracts\PaginatedResponse;
11
12
class Boards extends Provider
13
{
14
    use CanBeDeleted, Searchable, Followable;
15
16
    /**
17
     * @var array
18
     */
19
    protected $loginRequiredFor = [
20
        'delete',
21
        'create',
22
        'follow',
23
        'unFollow',
24
    ];
25
26
    protected $searchScope  = 'boards';
27
    protected $entityIdName = 'board_id';
28
    protected $followersFor = 'board_id';
29
30
    protected $followUrl    = UrlBuilder::RESOURCE_FOLLOW_BOARD;
31
    protected $unFollowUrl  = UrlBuilder::RESOURCE_UNFOLLOW_BOARD;
32
    protected $deleteUrl    = UrlBuilder::RESOURCE_DELETE_BOARD;
33
    protected $followersUrl = UrlBuilder::RESOURCE_BOARD_FOLLOWERS;
34
    
35
    /**
36
     * Get boards for user by username.
37
     *
38
     * @param string $username
39
     *
40
     * @return array|bool
41
     */
42
    public function forUser($username)
43
    {
44
        return $this->execGetRequest(['username' => $username], UrlBuilder::RESOURCE_GET_BOARDS);
45
    }
46
47
    /**
48
     * Get info about user's board.
49
     *
50
     * @param string $username
51
     * @param string $board
52
     *
53
     * @return array|bool
54
     */
55
    public function info($username, $board)
56
    {
57
        $requestOptions = [
58
            'username'      => $username,
59
            'slug'          => $board,
60
            'field_set_key' => 'detailed',
61
        ];
62
63
        return $this->execGetRequest($requestOptions, UrlBuilder::RESOURCE_GET_BOARD);
64
    }
65
66
    /**
67
     * Get pins from board by boardId.
68
     *
69
     * @param int $boardId
70
     * @param int $limit
71
     *
72
     * @return Generator
73
     */
74
    public function pins($boardId, $limit = 0)
75
    {
76
        return $this->getPaginatedResponse(['boardId' => $boardId], $limit, 'getPinsFromBoard');
77
    }
78
79
    /**
80
     * @param int   $boardId
81
     * @param array $bookmarks
82
     *
83
     * @return PaginatedResponse
84
     */
85
    public function getPinsFromBoard($boardId, $bookmarks = [])
86
    {
87
        return $this->execGetRequestWithPagination(
88
            ['board_id' => $boardId],
89
            UrlBuilder::RESOURCE_GET_BOARD_FEED,
90
            $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, UrlBuilder::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, UrlBuilder::RESOURCE_CREATE_BOARD);
135
    }
136
137
    /**
138
     * Returns title suggestions for pin.
139
     *
140
     * @param int $pinId
141
     * @return array|bool
142
     */
143
    public function titleSuggestionsFor($pinId)
144
    {
145
        return $this->execGetRequest(['pin_id' => $pinId], UrlBuilder::RESOURCE_TITLE_SUGGESTIONS);
146
    }
147
148
}
149