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

Inbox   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 77
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 2
dl 0
loc 77
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A news() 0 6 1
A notifications() 0 4 1
A conversations() 0 4 1
A sendMessage() 0 6 1
A sendEmail() 0 6 1
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