SMSWorks   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 20
dl 0
loc 58
rs 10
c 1
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 11 1
A sendMessage() 0 17 2
1
<?php
2
3
4
namespace BradleyKingDev\LaravelSMSWorks\Services;
5
6
7
use Swagger\Client\ApiException;
8
use Swagger\Client\Model\Message;
9
10
class SMSWorks
11
{
12
    /**
13
     * @var mixed
14
     */
15
    private $apiKey;
16
17
    /**
18
     * @var \Swagger\Client\Api\MessagesApi
19
     */
20
    private $apiInstance;
21
    /**
22
     * @var mixed
23
     */
24
    private $sender;
25
26
    /**
27
     * src constructor.
28
     */
29
    public function __construct()
30
    {
31
        $this->apiKey = env('SMSWORKS_KEY');
32
        $this->sender = env('SMSWORKS_SENDFROM');
33
34
        // Configure API key authorization: JWT
35
        $config = \Swagger\Client\Configuration::getDefaultConfiguration()->setApiKey('Authorization', $this->apiKey);
36
37
        $this->apiInstance = new \Swagger\Client\Api\MessagesApi(
38
            new \GuzzleHttp\Client(),
39
            $config
40
        );
41
    }
42
43
    /**
44
     * Send an src message
45
     *
46
     * @param string $destination
47
     * @param string $content
48
     * @return \Swagger\Client\Model\SendMessageResponse
49
     * @throws \Swagger\Client\ApiException
50
     */
51
    public function sendMessage(string $destination, string $content)
52
    {
53
        $data = [
54
            "sender" => $this->sender,
55
            "destination" => $destination,
56
            "content" => $content
57
        ];
58
59
        $sms_message = new Message($data);
60
61
        try {
62
            $result = $this->apiInstance->sendMessage($sms_message);
63
        } catch (\Exception | ApiException $e) {
64
            throw $e;
65
        }
66
67
        return $result;
68
    }
69
}