forked from arcturial/clickatell
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathClickatellRest.php
More file actions
80 lines (71 loc) · 2.32 KB
/
ClickatellRest.php
File metadata and controls
80 lines (71 loc) · 2.32 KB
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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
<?php
/**
* The Clickatell SMS Library provides a standardised way of talking to and
* receiving replies from the Clickatell API's. It makes it
* easier to write your applications and grants the ability to
* quickly switch the type of API you want to use HTTP/XML without
* changing any code.
*
* PHP Version 5.3
*
* @category Clickatell
* @package Clickatell
* @author Chris Brand <chris@cainsvault.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link https://github.com/arcturial
*/
namespace Clickatell;
use Clickatell\Component\Translate\TranslateJson as TranslateJson;
use Clickatell\Api\Api as Api;
use Clickatell\Exception\ApiException as ApiException;
use \Closure as Closure;
use Clickatell\Component\Event as Event;
use Clickatell\Component\Validate as Validate;
use \LogicException;
/**
* This is the main messenger class that encapsulates various objects to succesfully
* send Clickatell calls and respond in an appropriate manner. The messenger class
* enables you to set your own Transport and Translate interfaces.
*
* @category Clickatell
* @package Clickatell
* @author Chris Brand <chris@cainsvault.com>
* @license http://www.gnu.org/copyleft/gpl.html GNU General Public License
* @link https://github.com/arcturial
*/
class ClickatellRest extends Clickatell
{
/**
* The REST Transport Interface
* @var string
*/
const REST_API = "Clickatell\Api\Rest";
/**
* Clickatell Messenger Instantiation. Creates the Transport/Translate/Request
* interfaces required.
*
* @param string $token Clickatell auth token
*
* @return boolean
*/
public function __construct($token)
{
// Register autoloader
spl_autoload_register(array($this, '_autoLoad'));
// Create transport
$transport = self::REST_API;
$this->_transport = new $transport(new TranslateJson());
$this->_transport->authenticateByToken($token);
// Clear all registered events
Event::clear();
// Add validation listener using events
Event::on(
'request',
function ($data) {
$method = $data['call'];
$args = $data['request'];
Validate::processValidation($method, $args);
}
);
}
}