1 | <?php |
||
14 | class ApiClient |
||
15 | { |
||
16 | /** |
||
17 | * Default API endpoint. |
||
18 | */ |
||
19 | protected $apiEndpoint; |
||
20 | |||
21 | /** |
||
22 | * Subscriber's API key. |
||
23 | */ |
||
24 | protected $apiKey; |
||
25 | |||
26 | /** |
||
27 | * Guzzle client instance. |
||
28 | */ |
||
29 | protected $guzzleClient; |
||
30 | |||
31 | /** |
||
32 | * Data converter instance. |
||
33 | */ |
||
34 | protected $converter = null; |
||
35 | |||
36 | /** |
||
37 | * Optional (recommended) setting of an API key when a new instance is instantiated. |
||
38 | * Setting the API endpoint, default or demo according to the (optional) parameter. |
||
39 | * Advanced users may wish to a Guzzle client with their own configuration settings |
||
40 | * but this will rarely be needed. |
||
41 | * |
||
42 | * @param string | null $apiKey |
||
43 | * @param boolean $demo |
||
44 | * @param GuzzleClient $guzzleClient |
||
45 | */ |
||
46 | public function __construct($apiKey = null, $demo = false, $guzzleClient = null) |
||
52 | |||
53 | /** |
||
54 | * Override default API endpoint. |
||
55 | * |
||
56 | * @param $apiEndpoint |
||
57 | */ |
||
58 | public function setApiEndpoint($demo = false) |
||
62 | |||
63 | /** |
||
64 | * Set or override the API key. |
||
65 | * |
||
66 | * @param $apiKey |
||
67 | */ |
||
68 | public function setApiKey($apiKey) |
||
72 | |||
73 | /** |
||
74 | * Accept the requested method and its parameters, make the request to XML Soccer and validate the response. |
||
75 | * |
||
76 | * @param $name |
||
77 | * @param $params |
||
78 | * @return SimpleXMLElement |
||
79 | */ |
||
80 | public function __call($method, $params) |
||
100 | |||
101 | public function json() |
||
107 | |||
108 | /** |
||
109 | * Build the base URI for the API from its endpoint and the resource being requested. |
||
110 | * |
||
111 | * @param $method |
||
112 | * @return string |
||
113 | */ |
||
114 | protected function buildUri($method) |
||
118 | |||
119 | /** |
||
120 | * Almost all API calls require an API Key so we add it to the parameters. |
||
121 | * |
||
122 | * @param $params |
||
123 | * @return string |
||
124 | */ |
||
125 | protected function prepareParams($method, $params) |
||
137 | |||
138 | /** |
||
139 | * Initialise or inject an instance of the Guzzle client. |
||
140 | * |
||
141 | * @return GuzzleClient |
||
142 | */ |
||
143 | protected function initGuzzleClient($guzzleClient = null) |
||
147 | |||
148 | /** |
||
149 | * Make the request to the XML Soccer service and validate response. |
||
150 | * |
||
151 | * @param string $uri |
||
152 | * @param array | null $params |
||
153 | * @throws RequestFailedException |
||
154 | * @return SimpleXMLElement |
||
155 | */ |
||
156 | protected function request($uri, $params) |
||
166 | } |
||
167 |