Completed
Pull Request — master (#308)
by Sergey
06:18
created

Inbox::ignoreContactRequest()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 6
rs 9.4285
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
use seregazhuk\PinterestBot\Api\Providers\Core\Provider;
10
11
class Inbox extends Provider
12
{
13
    use SendsMessages;
14
15
    /**
16
     * @var array
17
     */
18
    protected $loginRequiredFor = [
19
        'news',
20
        'sendEmail',
21
        'sendMessage',
22
        'notifications',
23
        'contactRequests',
24
        'conversations',
25
    ];
26
27
    /**
28
     * @param int $limit
29
     * @return Pagination
30
     */
31
    public function news($limit = Pagination::DEFAULT_LIMIT)
32
    {
33
        $data = ['allow_stale' => true];
34
35
        return $this->paginate(UrlBuilder::RESOURCE_GET_LATEST_NEWS, $data, $limit);
36
    }
37
38
    /**
39
     * @param int $limit
40
     * @return Pagination
41
     */
42
    public function notifications($limit = Pagination::DEFAULT_LIMIT)
43
    {
44
        return $this->paginate(UrlBuilder::RESOURCE_GET_NOTIFICATIONS, [], $limit);
45
    }
46
47
    /**
48
     * Get last user conversations.
49
     *
50
     * @return array|bool
51
     */
52
    public function conversations()
53
    {
54
        return $this->get(UrlBuilder::RESOURCE_GET_LAST_CONVERSATIONS);
55
    }
56
57
    /**
58
     * Send message to a user.
59
     *
60
     * @param array|string $userIds
61
     * @param string $text
62
     * @param int|null $pinId
63
     * @throws InvalidRequest
64
     * @return bool
65
     */
66
    public function sendMessage($userIds, $text, $pinId = null)
67
    {
68
        return $this->send($pinId, $text, $userIds, []);
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
        return $this->send($pinId, $text, [], $emails);
83
    }
84
85
    /**
86
     * Get current contact requests.
87
     *
88
     * @return array
89
     */
90
    public function contactRequests()
91
    {
92
        $requests = $this->get(UrlBuilder::RESOURCE_CONTACTS_REQUESTS);
93
94
        return !$requests ? [] : $requests;
95
    }
96
97
    /**
98
     * @param string $requestId
99
     * @return bool
100
     */
101
    public function acceptContactRequest($requestId)
102
    {
103
        return $this->makeContactRequestCall(
104
            $requestId, UrlBuilder::RESOURCE_CONTACT_REQUEST_ACCEPT
105
        );
106
    }
107
108
    /**
109
     * @param string $requestId
110
     * @return bool
111
     */
112
    public function ignoreContactRequest($requestId)
113
    {
114
        return $this->makeContactRequestCall(
115
            $requestId, UrlBuilder::RESOURCE_CONTACT_REQUEST_IGNORE
116
        );
117
    }
118
119
    /**
120
     * @param string $requestId
121
     * @param $endpoint
122
     * @return bool
123
     */
124
    protected function makeContactRequestCall($requestId, $endpoint)
125
    {
126
        $data = [
127
            'contact_request' => [
128
                "type" => "contactrequest",
129
                "id"   => $requestId,
130
            ],
131
        ];
132
133
        return $this->post($endpoint, $data);
134
    }
135
}
136