Completed
Push — master ( af7c86...2260a0 )
by Kazi Mainuddin
03:11
created

Melipayamak::getSmsResponse()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 14
rs 9.7998
c 0
b 0
f 0
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Tzsk\Sms\Drivers;
4
5
use Tzsk\Sms\Abstracts\Driver;
6
use Melipayamak\MelipayamakApi;
7
8
class Melipayamak extends Driver
9
{
10
    /**
11
     * Melipayamak Settings.
12
     *
13
     * @var object
14
     */
15
    protected $settings;
16
17
    /**
18
     * Melipayamak Client.
19
     *
20
     * @var MelipayamakApi
21
     */
22
    protected $client;
23
24
    /**
25
     * Construct the class with the relevant settings.
26
     *
27
     * SendSmsInterface constructor.
28
     * @param $settings object
29
     */
30
    public function __construct($settings)
31
    {
32
        $this->settings = (object) $settings;
33
        $this->client = new MelipayamakApi($this->settings->username, $this->settings->password);
34
    }
35
36
    /**
37
     * Determine if the sms must be a flash message or not.
38
     *
39
     * @param bool $flash
40
     * @return $this
41
     */
42
    public function asFlash($flash = true)
43
    {
44
        $this->settings->flash = $flash;
45
46
        return $this;
47
    }
48
49
    /**
50
     * Send text message and return response.
51
     *
52
     * @return object
53
     */
54
    public function send()
55
    {
56
        $response = collect();
57
        foreach ($this->recipients as $recipient) {
58
            $response->put($recipient, $this->client->sms()->send(
59
                $recipient,
60
                $this->settings->from,
61
                $this->body,
62
                $this->settings->flash
63
            ));
64
        }
65
66
        return (count($this->recipients) == 1) ? $response->first() : $response;
67
    }
68
}
69