Conditions | 1 |
Paths | 1 |
Total Lines | 34 |
Code Lines | 21 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
40 | public function notify($data) |
||
41 | { |
||
42 | $client = new Client(); |
||
43 | $request = new Request( |
||
44 | 'POST', |
||
45 | $this->webhookUrl, |
||
46 | ['Content-type' => 'application/json'], |
||
47 | json_encode($data) |
||
48 | ); |
||
49 | |||
50 | $promise = $client->sendAsync($request, ['timeout' => 10]); |
||
51 | |||
52 | $promise->then( |
||
53 | function(ResponseInterface $res) use ($data) { |
||
54 | $this->logger->info( |
||
55 | sprintf( |
||
56 | 'Request to SLACK webhook OK [%s] with data: %s', |
||
57 | $res->getStatusCode(), |
||
58 | json_encode($data) |
||
59 | ) |
||
60 | ); |
||
61 | }, |
||
62 | function(RequestException $e) { |
||
63 | $this->logger->error( |
||
64 | sprintf( |
||
65 | 'Request to SLACK webhook FAILED with message: %s', |
||
66 | $e->getMessage() |
||
67 | ) |
||
68 | ); |
||
69 | } |
||
70 | ); |
||
71 | |||
72 | $promise->wait(false); |
||
73 | } |
||
74 | } |
||
75 |