Completed
Push — master ( ccd20f...6ee4e9 )
by dan
02:09
created

SlackWebhookMessageDispatcher   A

Complexity

Total Complexity 1

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 1
lcom 0
cbo 1
dl 0
loc 23
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A dispatch() 0 20 1
1
<?php
2
3
namespace IrishDan\NotificationBundle\Dispatcher;
4
5
use IrishDan\NotificationBundle\Message\MessageInterface;
6
use Nexmo\Client;
7
8
class SlackWebhookMessageDispatcher implements MessageDispatcherInterface
9
{
10
    public function dispatch(MessageInterface $message)
11
    {
12
        // Get the dispatch and message data from the message.
13
        $dispatchData = $message->getDispatchData();
14
        $messageData  = $message->getMessageData();
15
16
        $msg = $messageData['body'];
17
        $url = $dispatchData['webhook'];
18
19
        // @TODO: Build from message data.
20
        $payload = 'payload={"text": "' . $msg . '", "icon_emoji": ":ghost:"}';
21
22
        $ch = curl_init();
23
        curl_setopt($ch, CURLOPT_POST, true); //set how many paramaters to post
24
        curl_setopt($ch, CURLOPT_URL, $url);
25
        curl_setopt($ch, CURLOPT_POSTFIELDS, $payload);
26
27
        curl_exec($ch); //execute and get the results
28
        curl_close($ch);
29
    }
30
}