1 | <?php |
||
8 | class Client |
||
9 | { |
||
10 | /** |
||
11 | * Contains cURL instance. |
||
12 | */ |
||
13 | public $ch; |
||
14 | |||
15 | /** |
||
16 | * Contains the authentication string. |
||
17 | */ |
||
18 | protected $secret_token; |
||
19 | |||
20 | protected $grant_token; |
||
21 | |||
22 | /** |
||
23 | * __construct function. |
||
24 | * |
||
25 | * Instantiate object |
||
26 | * |
||
27 | * @param string $secret_token |
||
28 | * @param string $grant_token |
||
29 | * |
||
30 | * @throws Exception |
||
31 | */ |
||
32 | 15 | public function __construct($secret_token = '', $grant_token = '') |
|
33 | { |
||
34 | // Check if lib cURL is enabled |
||
35 | 15 | if (!function_exists('curl_init')) { |
|
36 | throw new Exception('Lib cURL must be enabled on the server'); |
||
37 | } |
||
38 | |||
39 | 15 | if (empty($secret_token)) { |
|
40 | 1 | throw new Exception('secret token is missing'); |
|
41 | } |
||
42 | |||
43 | 14 | if (empty($grant_token)) { |
|
44 | 1 | throw new Exception('grant token is missing'); |
|
45 | } |
||
46 | |||
47 | // Set auth string property |
||
48 | 13 | $this->secret_token = $secret_token; |
|
49 | 13 | $this->grant_token = $grant_token; |
|
50 | 13 | } |
|
51 | |||
52 | /** |
||
53 | * Shutdown function. |
||
54 | * |
||
55 | * Closes the current cURL connection |
||
56 | */ |
||
57 | 8 | public function shutdown() |
|
63 | |||
64 | /** |
||
65 | * Create function. |
||
66 | * |
||
67 | * Create cURL connection with authentication |
||
68 | */ |
||
69 | 8 | public function create() |
|
81 | |||
82 | /** |
||
83 | * authenticate function. |
||
84 | * |
||
85 | * Create authentication headers |
||
86 | */ |
||
87 | 8 | protected function authenticate() |
|
112 | } |
||
113 |