|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\Wunderlist; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
|
6
|
|
|
use Illuminate\Support\Arr; |
|
7
|
|
|
use NotificationChannels\Wunderlist\Exceptions\CouldNotSendNotification; |
|
8
|
|
|
use Illuminate\Notifications\Notification; |
|
9
|
|
|
use NotificationChannels\Wunderlist\Exceptions\InvalidConfiguration; |
|
10
|
|
|
|
|
11
|
|
|
class WunderlistChannel |
|
12
|
|
|
{ |
|
13
|
|
|
const API_ENDPOINT = 'https://a.wunderlist.com/api/v1/tasks'; |
|
14
|
|
|
|
|
15
|
|
|
/** @var Client */ |
|
16
|
|
|
protected $client; |
|
17
|
|
|
|
|
18
|
|
|
/** |
|
19
|
|
|
* @param Client $client |
|
20
|
|
|
*/ |
|
21
|
3 |
|
public function __construct(Client $client) |
|
22
|
|
|
{ |
|
23
|
3 |
|
$this->client = $client; |
|
24
|
3 |
|
} |
|
25
|
|
|
|
|
26
|
|
|
/** |
|
27
|
|
|
* Send the given notification. |
|
28
|
|
|
* |
|
29
|
|
|
* @param mixed $notifiable |
|
30
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
|
31
|
|
|
* |
|
32
|
|
|
* @throws \NotificationChannels\Wunderlist\Exceptions\InvalidConfiguration |
|
33
|
|
|
* @throws \NotificationChannels\Wunderlist\Exceptions\CouldNotSendNotification |
|
34
|
|
|
*/ |
|
35
|
3 |
|
public function send($notifiable, Notification $notification) |
|
36
|
|
|
{ |
|
37
|
3 |
|
$routing = collect($notifiable->routeNotificationFor('Wunderlist')); |
|
38
|
|
|
|
|
39
|
3 |
|
if (! Arr::has($routing, ['token', 'list_id'])) { |
|
40
|
|
|
return; |
|
41
|
|
|
} |
|
42
|
|
|
|
|
43
|
3 |
|
$key = config('services.wunderlist.key'); |
|
44
|
|
|
|
|
45
|
3 |
|
if (is_null($key)) { |
|
46
|
1 |
|
throw InvalidConfiguration::configurationNotSet(); |
|
47
|
|
|
} |
|
48
|
|
|
|
|
49
|
2 |
|
$wunderlistParameters = $notification->toWunderlist($notifiable)->toArray(); |
|
|
|
|
|
|
50
|
|
|
|
|
51
|
2 |
|
$response = $this->client->post(self::API_ENDPOINT, [ |
|
52
|
2 |
|
'body' => json_encode(Arr::set($wunderlistParameters, 'list_id', (int) $routing->get('list_id'))), |
|
53
|
|
|
'headers' => [ |
|
54
|
2 |
|
'X-Client-ID' => $key, |
|
55
|
2 |
|
'X-Access-Token' => $routing->get('token'), |
|
56
|
2 |
|
'Content-Type' => 'application/json', |
|
57
|
|
|
], |
|
58
|
|
|
]); |
|
59
|
|
|
|
|
60
|
2 |
|
if ($response->getStatusCode() !== 201) { |
|
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.