Completed
Pull Request — master (#216)
by Sergey
03:15 queued 46s
created

Boards::getPinsFromBoard()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 8
c 0
b 0
f 0
rs 9.4285
cc 1
eloc 5
nc 1
nop 2
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\Traits\SendsMessages;
11
use seregazhuk\PinterestBot\Api\Contracts\PaginatedResponse;
12
13
class Boards extends Provider
14
{
15
    use CanBeDeleted, Searchable, Followable, SendsMessages;
16
17
    /**
18
     * @var array
19
     */
20
    protected $loginRequiredFor = [
21
        'delete',
22
        'create',
23
        'follow',
24
        'unFollow',
25
        'send',
26
    ];
27
28
    protected $searchScope  = 'boards';
29
    protected $entityIdName = 'board_id';
30
    protected $followersFor = 'board_id';
31
32
    protected $followUrl    = UrlBuilder::RESOURCE_FOLLOW_BOARD;
33
    protected $unFollowUrl  = UrlBuilder::RESOURCE_UNFOLLOW_BOARD;
34
    protected $deleteUrl    = UrlBuilder::RESOURCE_DELETE_BOARD;
35
    protected $followersUrl = UrlBuilder::RESOURCE_BOARD_FOLLOWERS;
36
    
37
    /**
38
     * Get boards for user by username.
39
     *
40
     * @param string $username
41
     *
42
     * @return array|bool
43
     */
44
    public function forUser($username)
45
    {
46
        return $this->execGetRequest(['username' => $username], UrlBuilder::RESOURCE_GET_BOARDS);
47
    }
48
49
    /**
50
     * Get info about user's board.
51
     *
52
     * @param string $username
53
     * @param string $board
54
     *
55
     * @return array|bool
56
     */
57
    public function info($username, $board)
58
    {
59
        $requestOptions = [
60
            'username'      => $username,
61
            'slug'          => $board,
62
            'field_set_key' => 'detailed',
63
        ];
64
65
        return $this->execGetRequest($requestOptions, UrlBuilder::RESOURCE_GET_BOARD);
66
    }
67
68
    /**
69
     * Get pins from board by boardId.
70
     *
71
     * @param int $boardId
72
     * @param int $limit
73
     *
74
     * @return Generator
75
     */
76
    public function pins($boardId, $limit = 0)
77
    {
78
        return $this->getPaginatedResponse(['boardId' => $boardId], $limit, 'getPinsFromBoard');
79
    }
80
81
    /**
82
     * @param int   $boardId
83
     * @param array $bookmarks
84
     *
85
     * @return PaginatedResponse
86
     */
87
    public function getPinsFromBoard($boardId, $bookmarks = [])
88
    {
89
        return $this->execGetRequestWithPagination(
90
            ['board_id' => $boardId],
91
            UrlBuilder::RESOURCE_GET_BOARD_FEED,
92
            $bookmarks
93
        );
94
    }
95
96
    /**
97
     * Update board info. Gets boardId and an associative array as params. Available keys of the array are:
98
     * 'category', 'description', 'privacy'.
99
     *
100
     * - 'privacy' can be 'public' or 'secret'. 'public' by default.
101
     * - 'category' is 'other' by default.
102
     *
103
     * @param $boardId
104
     * @param $attributes
105
     * @return mixed
106
     */
107
    public function update($boardId, $attributes)
108
    {
109
        $requestOptions = array_merge(
110
            [
111
                'board_id' => $boardId,
112
                'category' => 'other',
113
            ], $attributes
114
        );
115
116
        return $this->execPostRequest($requestOptions, UrlBuilder::RESOURCE_UPDATE_BOARD);
117
    }
118
119
    /**
120
     * Create a new board.
121
     *
122
     * @param string $name
123
     * @param string $description
124
     * @param string $privacy     Can be 'public' or 'secret'. 'public' by default.
125
     *
126
     * @return bool
127
     */
128
    public function create($name, $description, $privacy = 'public')
129
    {
130
        $requestOptions = [
131
            'name'        => $name,
132
            'description' => $description,
133
            'privacy'     => $privacy,
134
        ];
135
136
        return $this->execPostRequest($requestOptions, UrlBuilder::RESOURCE_CREATE_BOARD);
137
    }
138
139
    /**
140
     * Returns title suggestions for pin.
141
     *
142
     * @param string $pinId
143
     * @return array|bool
144
     */
145
    public function titleSuggestionsFor($pinId)
146
    {
147
        return $this->execGetRequest(['pin_id' => $pinId], UrlBuilder::RESOURCE_TITLE_SUGGESTIONS);
148
    }
149
150
    /**
151
     * Send board with message or by email.
152
     *
153
     * @param int $boardId
154
     * @param string $text
155
     * @param array|int $userIds
156
     * @param array|int $emails
157
     * @return bool
158
     */
159
    public function send($boardId, $text, $userIds, $emails)
160
    {
161
        $messageData = $this->buildMessageData($text, $boardId);
162
163
        return $this->callSendMessage($userIds, $emails, $messageData);
0 ignored issues
show
Bug introduced by
It seems like $emails defined by parameter $emails on line 159 can also be of type integer; however, seregazhuk\PinterestBot\...ages::callSendMessage() does only seem to accept array|string, maybe add an additional type check?

This check looks at variables that have been passed in as parameters and are passed out again to other methods.

If the outgoing method call has stricter type requirements than the method itself, an issue is raised.

An additional type check may prevent trouble.

Loading history...
164
    }
165
}
166