Completed
Pull Request — master (#296)
by Sergey
02:05
created

Inbox::ignoreContactRequests()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 11
Code Lines 6

Duplication

Lines 11
Ratio 100 %

Importance

Changes 0
Metric Value
cc 1
eloc 6
nc 1
nop 1
dl 11
loc 11
rs 9.4285
c 0
b 0
f 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
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
        'conversations',
24
    ];
25
26
    /**
27
     * @param int $limit
28
     * @return Pagination
29
     */
30
    public function news($limit = Pagination::DEFAULT_LIMIT)
31
    {
32
        $data = ['allow_stale' => true];
33
34
        return $this->paginate($data, UrlBuilder::RESOURCE_GET_LATEST_NEWS, $limit);
35
    }
36
37
    /**
38
     * @param int $limit
39
     * @return Pagination
40
     */
41
    public function notifications($limit = Pagination::DEFAULT_LIMIT)
42
    {
43
        return $this->paginate([], UrlBuilder::RESOURCE_GET_NOTIFICATIONS, $limit);
44
    }
45
46
    /**
47
     * Get last user conversations.
48
     *
49
     * @return array|bool
50
     */
51
    public function conversations()
52
    {
53
        return $this->get([], UrlBuilder::RESOURCE_GET_LAST_CONVERSATIONS);
54
    }
55
56
    /**
57
     * Send message to a user.
58
     *
59
     * @param array|string $userIds
60
     * @param string $text
61
     * @param int|null $pinId
62
     * @throws InvalidRequest
63
     * @return bool
64
     */
65
    public function sendMessage($userIds, $text, $pinId = null)
66
    {
67
        return $this->send($pinId, $text, $userIds, []);
68
    }
69
70
    /**
71
     * Send email.
72
     *
73
     * @param array|string $emails
74
     * @param string $text
75
     * @param int|null $pinId
76
     * @throws InvalidRequest
77
     * @return bool
78
     */
79
    public function sendEmail($emails, $text, $pinId = null)
80
    {
81
        return $this->send($pinId, $text, [], $emails);
82
    }
83
84
    public function contactRequests()
85
    {
86
        $requests = $this->get([], UrlBuilder::RESOURCE_CONTACTS_REQUESTS);
87
88
        return !$requests ? [] : $requests;
89
    }
90
91
    /**
92
     * @param string $requestId
93
     * @return bool
94
     */
95 View Code Duplication
    public function acceptContactRequest($requestId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
96
    {
97
        $data = [
98
            'contact_request' => [
99
                "type" => "contactrequest",
100
                "id"   => $requestId,
101
            ],
102
        ];
103
104
        return $this->post($data, UrlBuilder::RESOURCE_CONTACT_REQUEST_ACCEPT);
105
    }
106
107
    /**
108
     * @param string $requestId
109
     * @return bool
110
     */
111 View Code Duplication
    public function ignoreContactRequests($requestId)
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
112
    {
113
        $data = [
114
            'contact_request' => [
115
                "type" => "contactrequest",
116
                "id"   => $requestId,
117
            ],
118
        ];
119
120
        return $this->post($data, UrlBuilder::RESOURCE_CONTACT_REQUEST_IGNORE);
121
    }
122
}
123