-
Notifications
You must be signed in to change notification settings - Fork 30
Expand file tree
/
Copy pathCurlTransport.php
More file actions
58 lines (44 loc) · 1.67 KB
/
CurlTransport.php
File metadata and controls
58 lines (44 loc) · 1.67 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
<?php
class SparkAPI_CurlTransport extends SparkAPI_CoreTransport implements SparkAPI_TransportInterface {
protected $ch = null;
function __construct() {
// initialize cURL for use later
$this->ch = curl_init();
curl_setopt($this->ch, CURLOPT_HEADER, false);
curl_setopt($this->ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($this->ch, CURLOPT_TIMEOUT, 0);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($this->ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($this->ch, CURLOPT_ENCODING, "gzip");
curl_setopt($this->ch, CURLOPT_SSLVERSION, 6);
}
function __destruct() {
// clean cURL up
curl_close($this->ch);
}
function make_request($request = array()) {
$request_headers_flat = "";
foreach ($request['headers'] as $k => $v) {
$request_headers_flat .= "{$k}: {$v}\r\n";
}
$full_url = $request['protocol'] .'://'. $request['host'] . $request['uri'];
if ( !empty($request['query_string']) ) {
$full_url .= '?'. $request['query_string'];
}
curl_setopt($this->ch, CURLOPT_URL, $full_url);
curl_setopt($this->ch, CURLOPT_CUSTOMREQUEST, $request['method']);
curl_setopt($this->ch, CURLOPT_POST, 0);
if ($request['method'] == "POST") {
curl_setopt($this->ch, CURLOPT_POST, 1);
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $request['post_data']);
}
elseif ($request['method'] == "PUT") {
curl_setopt($this->ch, CURLOPT_POSTFIELDS, $request['post_data']);
}
curl_setopt($this->ch, CURLOPT_HTTPHEADER, array(trim($request_headers_flat)));
$response_body = curl_exec($this->ch);
$response_info = curl_getinfo($this->ch);
$response_info['body'] = $response_body;
return $response_info;
}
}