Completed
Push — master ( 515296...4a3c26 )
by Sergey
56s
created

Boards::createPrivate()   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
c 0
b 0
f 0
rs 10
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace seregazhuk\PinterestBot\Api\Providers;
4
5
use seregazhuk\PinterestBot\Helpers\Pagination;
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\Traits\SendsMessages;
11
12
class Boards extends EntityProvider
13
{
14
    use CanBeDeleted, Searchable, Followable, SendsMessages;
15
16
    const BOARD_PRIVACY_PUBLIC = 'public';
17
    const BOARD_PRIVACY_PRIVATE = 'secret';
18
19
    /**
20
     * @var array
21
     */
22
    protected $loginRequiredFor = [
23
        'send',
24
        'delete',
25
        'create',
26
        'follow',
27
        'unFollow',
28
    ];
29
30
    protected $searchScope  = 'boards';
31
    protected $entityIdName = 'board_id';
32
    protected $followersFor = 'board_id';
33
34
    protected $followUrl    = UrlBuilder::RESOURCE_FOLLOW_BOARD;
35
    protected $unFollowUrl  = UrlBuilder::RESOURCE_UNFOLLOW_BOARD;
36
    protected $deleteUrl    = UrlBuilder::RESOURCE_DELETE_BOARD;
37
    protected $followersUrl = UrlBuilder::RESOURCE_BOARD_FOLLOWERS;
38
39
    protected $messageEntityName = 'board';
40
41
    /**
42
     * Get boards for user by username.
43
     *
44
     * @param string $username
45
     *
46
     * @return array|bool
47
     */
48
    public function forUser($username)
49
    {
50
        return $this->execGetRequest(['username' => $username], UrlBuilder::RESOURCE_GET_BOARDS);
51
    }
52
53
    /**
54
     * Get info about user's board.
55
     *
56
     * @param string $username
57
     * @param string $board
58
     *
59
     * @return array|bool
60
     */
61
    public function info($username, $board)
62
    {
63
        $requestOptions = [
64
            'username'      => $username,
65
            'slug'          => $board,
66
            'field_set_key' => 'detailed',
67
        ];
68
69
        return $this->execGetRequest($requestOptions, UrlBuilder::RESOURCE_GET_BOARD);
70
    }
71
72
    /**
73
     * Get pins from board by boardId.
74
     *
75
     * @param int $boardId
76
     * @param int $limit
77
     *
78
     * @return Pagination
79
     */
80
    public function pins($boardId, $limit = Pagination::DEFAULT_LIMIT)
81
    {
82
        return $this->paginate(
83
            ['board_id' => $boardId],
84
            UrlBuilder::RESOURCE_GET_BOARD_FEED,
85
            $limit
86
        );
87
    }
88
89
    /**
90
     * Update board info. Gets boardId and an associative array as params. Available keys of the array are:
91
     * 'category', 'description', 'privacy'.
92
     *
93
     * - 'privacy' can be 'public' or 'secret'. 'public' by default.
94
     * - 'category' is 'other' by default.
95
     *
96
     * @param $boardId
97
     * @param $attributes
98
     * @return mixed
99
     */
100
    public function update($boardId, $attributes)
101
    {
102
        $requestOptions = array_merge(
103
            [
104
                'board_id' => $boardId,
105
                'category' => 'other',
106
            ], $attributes
107
        );
108
109
        return $this->execPostRequest($requestOptions, UrlBuilder::RESOURCE_UPDATE_BOARD);
110
    }
111
112
    /**
113
     * Create a new board.
114
     *
115
     * @param string $name
116
     * @param string $description
117
     * @param string $privacy     Can be 'public' or 'secret'. 'public' by default.
118
     *
119
     * @return bool
120
     */
121
    public function create($name, $description, $privacy = self::BOARD_PRIVACY_PUBLIC)
122
    {
123
        $requestOptions = [
124
            'name'        => $name,
125
            'description' => $description,
126
            'privacy'     => $privacy,
127
        ];
128
129
        return $this->execPostRequest($requestOptions, UrlBuilder::RESOURCE_CREATE_BOARD);
130
    }
131
132
    /**
133
     * Create a new board.
134
     *
135
     * @codeCoverageIgnore
136
     * @param string $name
137
     * @param string $description
138
     *
139
     * @return bool
140
     */
141
    public function createPrivate($name, $description)
142
    {
143
       return $this->create($name, $description, self::BOARD_PRIVACY_PRIVATE);
144
    }
145
146
    /**
147
     * Returns title suggestions for pin.
148
     *
149
     * @param string $pinId
150
     * @return array|bool
151
     */
152
    public function titleSuggestionsFor($pinId)
153
    {
154
        return $this->execGetRequest(['pin_id' => $pinId], UrlBuilder::RESOURCE_TITLE_SUGGESTIONS);
155
    }
156
}
157