|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
namespace NotificationChannels\PivotalTracker; |
|
4
|
|
|
|
|
5
|
|
|
use GuzzleHttp\Client; |
|
6
|
|
|
use Illuminate\Notifications\Notification; |
|
7
|
|
|
use NotificationChannels\PivotalTracker\Exceptions\CouldNotSendNotification; |
|
8
|
|
|
|
|
9
|
|
|
class PivotalTrackerChannel |
|
10
|
|
|
{ |
|
11
|
|
|
const API_ENDPOINT = 'https://www.pivotal-tracker.com/services/v5/'; |
|
12
|
|
|
|
|
13
|
|
|
/** @var Client */ |
|
14
|
|
|
protected $client; |
|
15
|
|
|
|
|
16
|
|
|
/** @param Client $client */ |
|
17
|
|
|
public function __construct(Client $client) |
|
18
|
|
|
{ |
|
19
|
|
|
$this->client = $client; |
|
20
|
|
|
} |
|
21
|
|
|
|
|
22
|
|
|
/** |
|
23
|
|
|
* Send the given notification. |
|
24
|
|
|
* |
|
25
|
|
|
* @param mixed $notifiable |
|
26
|
|
|
* @param \Illuminate\Notifications\Notification $notification |
|
27
|
|
|
* |
|
28
|
|
|
* @throws \NotificationChannels\PivotalTracker\Exceptions\CouldNotSendNotification |
|
29
|
|
|
*/ |
|
30
|
|
|
public function send($notifiable, Notification $notification) |
|
31
|
|
|
{ |
|
32
|
|
|
if (! $routing = collect($notifiable->routeNotificationFor('PivotalTracker'))) { |
|
33
|
|
|
return; |
|
34
|
|
|
} |
|
35
|
|
|
|
|
36
|
|
|
$parameters = $notification->toPivotalTracker($notifiable)->toArray(); |
|
|
|
|
|
|
37
|
|
|
|
|
38
|
|
|
$response = $this->client->request('POST', $this->storiesEndpoint($routing->get('projectId')), [ |
|
39
|
|
|
'headers' => [ |
|
40
|
|
|
'X-TrackerToken' => $routing->get('token'), |
|
41
|
|
|
'Content-Type' => 'application/json', |
|
42
|
|
|
], |
|
43
|
|
|
'json' => $parameters, |
|
44
|
|
|
]); |
|
45
|
|
|
|
|
46
|
|
|
if ($response->getStatusCode() !== 200) { |
|
47
|
|
|
throw CouldNotSendNotification::serviceRespondedWithAnError($response); |
|
48
|
|
|
} |
|
49
|
|
|
} |
|
50
|
|
|
|
|
51
|
|
|
/** |
|
52
|
|
|
* Return the stories api endpoint for a given project. |
|
53
|
|
|
* |
|
54
|
|
|
* @param int $projectId the projet identifier |
|
55
|
|
|
* |
|
56
|
|
|
* @return string the stories endpoint |
|
57
|
|
|
*/ |
|
58
|
|
|
protected function storiesEndpoint($projectId) |
|
59
|
|
|
{ |
|
60
|
|
|
return self::API_ENDPOINT."projects/{$projectId}/stories"; |
|
61
|
|
|
} |
|
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.