Completed
Pull Request — master (#236)
by Sergey
06:25
created

Inbox::conversations()   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 0
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\SendsMessages;
8
use seregazhuk\PinterestBot\Exceptions\InvalidRequest;
9
10
class Inbox extends Provider
11
{
12
    use SendsMessages;
13
14
    /**
15
     * @var array
16
     */
17
    protected $loginRequiredFor = [
18
        'news',
19
        'sendEmail',
20
        'sendMessage',
21
        'notifications',
22
        'conversations',
23
    ];
24
25
    /**
26
     * @param int $limit
27
     * @return Pagination
28
     */
29
    public function news($limit = Pagination::DEFAULT_LIMIT)
30
    {
31
        $data = ['allow_stale' => true];
32
33
        return $this->paginate($data, UrlBuilder::RESOURCE_GET_LATEST_NEWS, $limit);
34
    }
35
36
    /**
37
     * @param int $limit
38
     * @return Pagination
39
     */
40
    public function notifications($limit = Pagination::DEFAULT_LIMIT)
41
    {
42
        return $this->paginate([], UrlBuilder::RESOURCE_GET_NOTIFICATIONS, $limit);
43
    }
44
45
    /**
46
     * Get last user conversations.
47
     *
48
     * @return array|bool
49
     */
50
    public function conversations()
51
    {
52
        return $this->execGetRequest([], UrlBuilder::RESOURCE_GET_LAST_CONVERSATIONS);
53
    }
54
55
    /**
56
     * Send message to a user.
57
     *
58
     * @param array|string $userIds
59
     * @param string $text
60
     * @param int|null $pinId
61
     * @throws InvalidRequest
62
     * @return bool
63
     */
64
    public function sendMessage($userIds, $text, $pinId = null)
65
    {
66
        $messageData = $this->buildMessageData($text, $pinId);
67
68
        return $this->callSendMessage($userIds, [], $messageData);
69
    }
70
71
    /**
72
     * Send email.
73
     *
74
     * @param array|string $emails
75
     * @param string $text
76
     * @param int|null $pinId
77
     * @throws InvalidRequest
78
     * @return bool
79
     */
80
    public function sendEmail($emails, $text, $pinId = null)
81
    {
82
        $messageData = $this->buildMessageData($text, $pinId);
83
84
        return $this->callSendMessage([], $emails, $messageData);
85
    }
86
}
87