1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace NotificationChannels\Engage; |
4
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
6
|
|
|
use Illuminate\Notifications\Notification; |
7
|
|
|
use NotificationChannels\Engage\Exceptions\CouldNotSendNotification; |
8
|
|
|
use NotificationChannels\Engage\Exceptions\InvalidConfiguration; |
9
|
|
|
|
10
|
|
|
class EngageChannel |
11
|
|
|
{ |
12
|
|
|
const API_ENDPOINT = 'https://pushcrew.com/api/v1/send/list'; |
13
|
|
|
|
14
|
|
|
/** @var \GuzzleHttp\Client */ |
15
|
|
|
protected $client; |
16
|
|
|
|
17
|
|
|
/** |
18
|
|
|
* @param \GuzzleHttp\Client $client |
19
|
|
|
*/ |
20
|
4 |
|
public function __construct(Client $client) |
21
|
|
|
{ |
22
|
4 |
|
$this->client = $client; |
23
|
4 |
|
} |
24
|
|
|
|
25
|
|
|
/** |
26
|
|
|
* Send the given notification. |
27
|
|
|
* |
28
|
|
|
* @param mixed $notifiable |
29
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
30
|
|
|
* |
31
|
|
|
* @throws \NotificationChannels\Engage\Exceptions\InvalidConfiguration |
32
|
|
|
* @throws \NotificationChannels\Engage\Exceptions\CouldNotSendNotification |
33
|
|
|
*/ |
34
|
4 |
|
public function send($notifiable, Notification $notification) |
35
|
|
|
{ |
36
|
4 |
|
$subscribers = collect($notifiable->routeNotificationFor('Engage')); |
37
|
|
|
|
38
|
4 |
|
if (! $subscribers->count()) { |
39
|
1 |
|
return; |
40
|
|
|
} |
41
|
|
|
|
42
|
3 |
|
if (! $token = config('services.vwo-engage.token')) { |
43
|
1 |
|
throw InvalidConfiguration::configurationNotSet(); |
44
|
|
|
} |
45
|
|
|
|
46
|
2 |
|
$message = $notification->toEngage($notifiable); |
|
|
|
|
47
|
|
|
|
48
|
2 |
|
$data = $message->toArray() + [ |
49
|
2 |
|
'subscriber_list' => json_encode([ |
50
|
2 |
|
'subscriber_list' => $subscribers, |
51
|
|
|
]), |
52
|
|
|
]; |
53
|
|
|
|
54
|
2 |
|
$response = $this->client->post(self::API_ENDPOINT, [ |
55
|
2 |
|
'headers' => ['Authorization' => $token], |
56
|
|
|
'http_errors' => false, |
57
|
2 |
|
'form_params' => $data, |
58
|
|
|
]); |
59
|
|
|
|
60
|
2 |
|
if ($response->getStatusCode() !== 200) { |
61
|
1 |
|
throw CouldNotSendNotification::serviceRespondedWithAnError($response); |
62
|
|
|
} |
63
|
1 |
|
} |
64
|
|
|
} |
65
|
|
|
|
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.