1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Twitter; |
4
|
|
|
|
5
|
|
|
use Abraham\TwitterOAuth\TwitterOAuth; |
6
|
|
|
use Illuminate\Notifications\Notification; |
7
|
|
|
use NotificationChannels\Twitter\Exceptions\CouldNotSendNotification; |
8
|
|
|
|
9
|
|
|
class TwitterChannel |
10
|
|
|
{ |
11
|
|
|
/** @var TwitterOAuth */ |
12
|
|
|
protected $twitter; |
13
|
|
|
|
14
|
|
|
/** |
15
|
|
|
* @param TwitterOAuth $twitter |
16
|
|
|
*/ |
17
|
3 |
|
public function __construct(TwitterOAuth $twitter) |
18
|
|
|
{ |
19
|
3 |
|
$this->twitter = $twitter; |
20
|
3 |
|
} |
21
|
|
|
|
22
|
|
|
/** |
23
|
|
|
* Send the given notification. |
24
|
|
|
* |
25
|
|
|
* @param mixed $notifiable |
26
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
27
|
|
|
* |
28
|
|
|
* @throws CouldNotSendNotification |
29
|
|
|
*/ |
30
|
3 |
|
public function send($notifiable, Notification $notification) |
31
|
|
|
{ |
32
|
3 |
|
if ($twitterSettings = $notifiable->routeNotificationFor('twitter')) { |
33
|
|
|
$this->switchSettings($twitterSettings); |
34
|
|
|
} |
35
|
|
|
|
36
|
3 |
|
$twitterMessage = $notification->toTwitter($notifiable); |
|
|
|
|
37
|
3 |
|
if (is_a($twitterMessage, TwitterStatusUpdate::class) && $twitterMessage->getImages()) { |
38
|
1 |
|
$this->twitter->setTimeouts(10, 15); |
39
|
|
|
|
40
|
1 |
|
$twitterMessage->imageIds = collect($twitterMessage->getImages())->map(function (TwitterImage $image) { |
41
|
1 |
|
$media = $this->twitter->upload('media/upload', ['media' => $image->getPath()]); |
42
|
|
|
|
43
|
1 |
|
return $media->media_id_string; |
44
|
1 |
|
}); |
45
|
|
|
} |
46
|
|
|
|
47
|
3 |
|
$this->twitter->post($twitterMessage->getApiEndpoint(), $twitterMessage->getRequestBody()); |
48
|
|
|
|
49
|
3 |
|
if ($this->twitter->getLastHttpCode() !== 200) { |
50
|
1 |
|
throw CouldNotSendNotification::serviceRespondedWithAnError($this->twitter->getLastBody()); |
51
|
|
|
} |
52
|
2 |
|
} |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* Use per user settings instead of default ones. |
56
|
|
|
* @param $twitterSettings |
57
|
|
|
*/ |
58
|
|
|
private function switchSettings($twitterSettings) |
59
|
|
|
{ |
60
|
|
|
$this->twitter = new TwitterOAuth($twitterSettings[0], $twitterSettings[1], $twitterSettings[2], |
61
|
|
|
$twitterSettings[3]); |
62
|
|
|
} |
63
|
|
|
} |
64
|
|
|
|
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.