|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace seregazhuk\PinterestBot\Api\Traits; |
|
4
|
|
|
|
|
5
|
|
|
use seregazhuk\PinterestBot\Helpers\UrlBuilder; |
|
6
|
|
|
|
|
7
|
|
|
trait CanBeShared |
|
8
|
|
|
{ |
|
9
|
|
|
use HandlesRequest, ResolvesCurrentUser; |
|
10
|
|
|
|
|
11
|
|
|
/** |
|
12
|
|
|
* @return array |
|
13
|
|
|
*/ |
|
14
|
|
|
protected function requiresLoginForCanBeShared() |
|
15
|
|
|
{ |
|
16
|
|
|
return [ |
|
17
|
|
|
'share', |
|
18
|
|
|
'markAsGood', |
|
19
|
|
|
'markAsBad', |
|
20
|
|
|
]; |
|
21
|
|
|
} |
|
22
|
|
|
|
|
23
|
|
|
/** |
|
24
|
|
|
* @param int $pinId |
|
25
|
|
|
* @return string |
|
26
|
|
|
*/ |
|
27
|
|
|
public function shareViaTwitter($pinId) |
|
28
|
|
|
{ |
|
29
|
|
|
return $this->share($pinId, $twitterChannel = 9); |
|
30
|
|
|
} |
|
31
|
|
|
|
|
32
|
|
|
/** |
|
33
|
|
|
* @param string $pinId |
|
34
|
|
|
* @param int $channel By default uses 12 (share via link) |
|
35
|
|
|
* @return string |
|
36
|
|
|
*/ |
|
37
|
|
|
public function share($pinId, $channel = 12) |
|
38
|
|
|
{ |
|
39
|
|
|
$request = [ |
|
40
|
|
|
"invite_type" => [ |
|
41
|
|
|
"invite_category" => 3, // magic numbers, but I have |
|
42
|
|
|
"invite_object" => 1, // no idea what do they mean |
|
43
|
|
|
"invite_channel" => $channel, |
|
44
|
|
|
], |
|
45
|
|
|
"object_id" => $pinId, |
|
46
|
|
|
]; |
|
47
|
|
|
|
|
48
|
|
|
$response = $this->post(UrlBuilder::RESOURCE_SHARE_VIA_SOCIAL, $request, true); |
|
49
|
|
|
|
|
50
|
|
|
var_dump($response); |
|
|
|
|
|
|
51
|
|
|
return isset($response['invite_url']) ? $response['invite_url'] : ''; |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* @param string $pinId |
|
56
|
|
|
* @param $userId |
|
57
|
|
|
* @return array|bool |
|
58
|
|
|
*/ |
|
59
|
|
|
public function leaveGoodReaction($pinId, $userId) |
|
60
|
|
|
{ |
|
61
|
|
|
return $this->reactOnPinInConversation($pinId, $userId, "👍"); |
|
62
|
|
|
} |
|
63
|
|
|
|
|
64
|
|
|
/** |
|
65
|
|
|
* @param string $pinId |
|
66
|
|
|
* @param $userId |
|
67
|
|
|
* @return array|bool |
|
68
|
|
|
*/ |
|
69
|
|
|
public function leaveBadReaction($pinId, $userId) |
|
70
|
|
|
{ |
|
71
|
|
|
return $this->reactOnPinInConversation($pinId, $userId, "👎"); |
|
72
|
|
|
} |
|
73
|
|
|
|
|
74
|
|
|
/** |
|
75
|
|
|
* @param string $pinId |
|
76
|
|
|
* @param string $userId |
|
77
|
|
|
* @param string $reaction |
|
78
|
|
|
* @return array|bool |
|
79
|
|
|
*/ |
|
80
|
|
|
protected function reactOnPinInConversation($pinId, $userId, $reaction) |
|
81
|
|
|
{ |
|
82
|
|
|
$request = [ |
|
83
|
|
|
"user_ids" => [$userId], |
|
84
|
|
|
"pin" => (string)$pinId, |
|
85
|
|
|
"text" => $reaction, |
|
86
|
|
|
]; |
|
87
|
|
|
|
|
88
|
|
|
return $this->post(UrlBuilder::RESOURCE_SEND_MESSAGE, $request); |
|
89
|
|
|
} |
|
90
|
|
|
} |
|
91
|
|
|
|