-
Notifications
You must be signed in to change notification settings - Fork 1
/
ImasysMessageSender.php
55 lines (44 loc) · 1.56 KB
/
ImasysMessageSender.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<?php
namespace Comsolit\ImasysMessageSenderBundle;
use Comsolit\ImasysPhp\Credentials;
use Comsolit\ImasysPhp\PortalServers;
use Comsolit\ImasysPhp\Connection;
use Comsolit\ImasysPhp\ApiMethods\SendMessageRequest;
use Comsolit\ImasysMessageSenderBundle\DataCollector\ImasysDataCollector;
use Comsolit\ImasysPhp\RequestInterface;
use Comsolit\ImasysPhp\ApiMethods\DeliveryDisabledResponse;
use Comsolit\ImasysPhp\Curl\Response as CurlResponse;
class ImasysMessageSender
{
private $connection;
private $originator;
private $collector;
private $deliveryDisabled;
public function __construct($originator, $deliveryDisabled, Connection $connection)
{
$this->connection = $connection;
$this->originator = $originator;
$this->deliveryDisabled = $deliveryDisabled;
}
public function setCollector(ImasysDataCollector $collector)
{
$this->collector = $collector;
}
public function sendMessage($message, $address)
{
$sendMessageRequest = new SendMessageRequest($message, $address, $this->originator);
return $this->send($sendMessageRequest);
}
private function send(RequestInterface $request)
{
if ($this->deliveryDisabled === true) {
$response = DeliveryDisabledResponse::parseResponse(new CurlResponse());
} else {
$response = $this->connection->send($request);
}
if ($this->collector instanceof ImasysDataCollector) {
$this->collector->collectHack($request, $response);
}
return $response;
}
}