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 |
|
if (! $routing = collect($notifiable->routeNotificationFor('Wunderlist'))) { |
38
|
|
|
return; |
39
|
|
|
} |
40
|
|
|
|
41
|
3 |
|
$key = config('services.wunderlist.key'); |
42
|
|
|
|
43
|
3 |
|
if (is_null($key)) { |
44
|
1 |
|
throw InvalidConfiguration::configurationNotSet(); |
45
|
|
|
} |
46
|
|
|
|
47
|
2 |
|
$wunderlistParameters = $notification->toWunderlist($notifiable)->toArray(); |
|
|
|
|
48
|
|
|
|
49
|
2 |
|
$response = $this->client->post(self::API_ENDPOINT, [ |
50
|
2 |
|
'body' => json_encode(Arr::set($wunderlistParameters, 'list_id', (int) $routing->get('list_id'))), |
51
|
|
|
'headers' => [ |
52
|
2 |
|
'X-Client-ID' => $key, |
53
|
2 |
|
'X-Access-Token' => $routing->get('token'), |
54
|
2 |
|
'Content-Type' => 'application/json', |
55
|
2 |
|
], |
56
|
2 |
|
]); |
57
|
|
|
|
58
|
2 |
|
if ($response->getStatusCode() !== 201) { |
59
|
1 |
|
throw CouldNotSendNotification::serviceRespondedWithAnError($response); |
60
|
|
|
} |
61
|
1 |
|
} |
62
|
|
|
} |
63
|
|
|
|
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.