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) |
|
|
|
|
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) |
|
|
|
|
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
|
|
|
|
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.