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