This repository has been archived by the owner on Apr 29, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAPI.php
65 lines (49 loc) · 1.41 KB
/
API.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
55
56
57
58
59
60
61
62
63
64
65
<?php
namespace T4G;
require 'API/Exception.php';
require 'API/Endpoint.php';
require 'API/Section.php';
require 'API/Config.php';
class API
{
public static $base = 'https://api.tools4games.com';
protected static $sections = [];
public static $api_key;
public static $api_secret;
public static function addSection(API\Section $section)
{
self::$sections[$section->id] = $section;
}
public static function execute($path, $query)
{
$path = self::$base . $path;
$path.= '?' .http_build_query($query);
#echo urldecode("\n$path\n");
if(function_exists('curl_version'))
{ // cURL is Available
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $path);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
$result = curl_exec($curl);
curl_close($curl);
}
else
{ // Use file_get_contents as fallback
$result = file_get_contents($path);
}
$result = json_decode($result);
return $result;
}
public function auth($key, $secret)
{
self::$api_key = $key;
self::$api_secret = $secret;
}
public function __call($method, $args)
{
$method = strToLower(str_replace('get', '', $method));
return self::$sections[$method];
}
}