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
|
|
|
public function acceptContactRequest($requestId) |
96
|
|
|
{ |
97
|
|
|
return $this->makeContactRequestCall( |
98
|
|
|
$requestId, UrlBuilder::RESOURCE_CONTACT_REQUEST_ACCEPT |
99
|
|
|
); |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* @param string $requestId |
104
|
|
|
* @return bool |
105
|
|
|
*/ |
106
|
|
|
public function ignoreContactRequests($requestId) |
107
|
|
|
{ |
108
|
|
|
return $this->makeContactRequestCall( |
109
|
|
|
$requestId, UrlBuilder::RESOURCE_CONTACT_REQUEST_IGNORE |
110
|
|
|
); |
111
|
|
|
} |
112
|
|
|
|
113
|
|
|
/** |
114
|
|
|
* @param string $requestId |
115
|
|
|
* @param $endpoint |
116
|
|
|
* @return bool |
117
|
|
|
*/ |
118
|
|
|
protected function makeContactRequestCall($requestId, $endpoint) |
119
|
|
|
{ |
120
|
|
|
$data = [ |
121
|
|
|
'contact_request' => [ |
122
|
|
|
"type" => "contactrequest", |
123
|
|
|
"id" => $requestId, |
124
|
|
|
], |
125
|
|
|
]; |
126
|
|
|
|
127
|
|
|
return $this->post($data, $endpoint); |
128
|
|
|
} |
129
|
|
|
} |
130
|
|
|
|