1 | <?php |
||
5 | class Drip |
||
6 | { |
||
7 | protected static $eventSubscriptions = []; |
||
8 | protected static $receivedWebhook = false; |
||
9 | protected $api_endpoint = 'https://api.getdrip.com/v2'; |
||
10 | protected $token = false; |
||
11 | protected $accountID = null; |
||
12 | protected $verify_ssl = true; |
||
13 | |||
14 | /** |
||
15 | * Drip constructor. |
||
16 | * |
||
17 | * @param string $token API Token |
||
18 | * @param string|null $accountID Drip account ID to operate on |
||
19 | */ |
||
20 | public function __construct($token, $accountID = null) |
||
28 | |||
29 | public static function subscribeToWebhook($event, callable $callback) |
||
38 | |||
39 | public static function receiveWebhook($input = null) |
||
55 | |||
56 | protected static function processWebhook($input) |
||
69 | |||
70 | protected static function dispatchWebhookEvent($event, $data) |
||
81 | |||
82 | /** |
||
83 | * Set account ID if it was not passed into the constructor |
||
84 | * |
||
85 | * @param string $accountID |
||
86 | * |
||
87 | * @return void |
||
88 | */ |
||
89 | public function setAccountId($accountID) |
||
93 | |||
94 | /** |
||
95 | * Make a GET request |
||
96 | * |
||
97 | * @param string $api_method API method to call |
||
98 | * @param array $args API arguments |
||
99 | * @param int $timeout Connection timeout (seconds) |
||
100 | * |
||
101 | * @return Response |
||
102 | * @throws DripException |
||
103 | */ |
||
104 | public function get($api_method, $args = [], $timeout = 10) |
||
108 | |||
109 | /** |
||
110 | * Make the HTTP request |
||
111 | * |
||
112 | * @param string $http_verb HTTP method used: get, post, delete |
||
113 | * @param string $api_method Drip API method to call |
||
114 | * @param array $args Array of arguments to the API method |
||
115 | * @param int $timeout Connection timeout (seconds) |
||
116 | * @param string $url Optional URL to override the constructed one |
||
117 | * |
||
118 | * @return Response |
||
119 | * @throws DripException |
||
120 | */ |
||
121 | protected function makeRequest($http_verb, $api_method, $args = [], $timeout = 10, $url = null) |
||
145 | |||
146 | /** |
||
147 | * Check for required PHP functionality |
||
148 | * |
||
149 | * @return bool |
||
150 | * @throws DripException |
||
151 | */ |
||
152 | private function checkDependencies() |
||
160 | |||
161 | /** |
||
162 | * @param string|null $url |
||
163 | * @param string $api_method |
||
164 | * |
||
165 | * @return string |
||
166 | * @throws DripException |
||
167 | */ |
||
168 | private function constructRequestUrl($url, $api_method) |
||
180 | |||
181 | /** |
||
182 | * Create a new CURL session (common setup etc) |
||
183 | * |
||
184 | * @param string $url |
||
185 | * @param int $timeout |
||
186 | * |
||
187 | * @return resource |
||
188 | * @throws DripException |
||
189 | */ |
||
190 | private function createCurlSession($url, $timeout = 10) |
||
213 | |||
214 | /** |
||
215 | * Execute and handle the request result |
||
216 | * |
||
217 | * @param resource $ch Curl handle |
||
218 | * |
||
219 | * @return Response |
||
220 | * @throws DripException |
||
221 | */ |
||
222 | private function executeRequest(&$ch) |
||
239 | |||
240 | /** |
||
241 | * Make a GET request to a top-level method outside of this account |
||
242 | * |
||
243 | * @param string $api_method |
||
244 | * @param array $args |
||
245 | * @param int $timeout |
||
246 | * |
||
247 | * @return Response |
||
248 | * @throws DripException |
||
249 | */ |
||
250 | public function getGlobal($api_method, $args = [], $timeout = 10) |
||
255 | |||
256 | /** |
||
257 | * Make a POST request |
||
258 | * |
||
259 | * @param string $api_method API method |
||
260 | * @param array $args Arguments to API method |
||
261 | * @param int $timeout Connection timeout (seconds) |
||
262 | * |
||
263 | * @return Response |
||
264 | * @throws DripException |
||
265 | */ |
||
266 | public function post($api_method, $args = [], $timeout = 10) |
||
270 | |||
271 | /** |
||
272 | * Make a DELETE request |
||
273 | * |
||
274 | * @param string $api_method API method |
||
275 | * @param array $args Arguments to the API method |
||
276 | * @param int $timeout Connection timeout (seconds) |
||
277 | * |
||
278 | * @return Response |
||
279 | * @throws DripException |
||
280 | */ |
||
281 | public function delete($api_method, $args = [], $timeout = 10) |
||
285 | |||
286 | public function disableSSLVerification() |
||
290 | } |
||
291 |
This check looks for assignments to scalar types that may be of the wrong type.
To ensure the code behaves as expected, it may be a good idea to add an explicit type cast.