-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathOpenXBL.php
54 lines (45 loc) · 1.3 KB
/
OpenXBL.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
<?php
class OpenXBL
{
private $url_base = "https://xbl.io/api/";
private $version = "v1";
var $key;
public function __construct($apiKey)
{
$this->key = $apiKey;
}
public function call($method, $url, $options = array())
{
$crl = curl_init($this->url_base . $this->version . $url);
$headr = array();
if( !empty( $options['headers'] ) )
{
foreach( $options['headers'] as $header => $value )
{
$headr[] = $header . ':' . $value;
}
}
// pass in the key
$headr[] = 'X-Authorization: ' . $this->key;
curl_setopt($crl, CURLOPT_HTTPHEADER,$headr);
curl_setopt($crl, CURLOPT_RETURNTRANSFER, 1);
if($method == 'POST')
{
if( !empty( $options['payload'] ) )
{
curl_setopt( $crl, CURLOPT_POSTFIELDS, json_encode( $options['payload'] ) );
}
curl_setopt($crl, CURLOPT_POST,true);
}
else if( $method == 'GET' )
{
curl_setopt($crl, CURLOPT_POST,false);
}
else
{
curl_setopt($crl, CURLOPT_CUSTOMREQUEST, $method);
}
$results = json_decode(curl_exec($crl), true);
return $results['data'];
}
}