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 | * Should data be returned as a json encoded string? |
||
38 | */ |
||
39 | protected $encode = false; |
||
40 | |||
41 | /** |
||
42 | * Optional (recommended) setting of an API key when a new instance is instantiated. |
||
43 | * Setting the API endpoint, default or demo according to the (optional) parameter. |
||
44 | * Advanced users may wish to a Guzzle client with their own configuration settings |
||
45 | * but this will rarely be needed. |
||
46 | * |
||
47 | * @param string | null $apiKey |
||
48 | * @param boolean $demo |
||
49 | * @param GuzzleClient $guzzleClient |
||
50 | */ |
||
51 | public function __construct($apiKey = null, $demo = false, $guzzleClient = null) |
||
57 | |||
58 | /** |
||
59 | * Override default API endpoint. |
||
60 | * |
||
61 | * @param $apiEndpoint |
||
62 | */ |
||
63 | public function setApiEndpoint($demo = false) |
||
67 | |||
68 | /** |
||
69 | * Set or override the API key. |
||
70 | * |
||
71 | * @param $apiKey |
||
72 | */ |
||
73 | public function setApiKey($apiKey) |
||
77 | |||
78 | /** |
||
79 | * Accept the requested method and its parameters, make the request to XML Soccer and validate the response. |
||
80 | * |
||
81 | * @param $name |
||
82 | * @param $params |
||
83 | * @return SimpleXMLElement |
||
84 | */ |
||
85 | public function __call($method, $params) |
||
107 | |||
108 | public function object() |
||
114 | |||
115 | public function json() |
||
121 | |||
122 | /** |
||
123 | * Build the base URI for the API from its endpoint and the resource being requested. |
||
124 | * |
||
125 | * @param $method |
||
126 | * @return string |
||
127 | */ |
||
128 | protected function buildUri($method) |
||
132 | |||
133 | /** |
||
134 | * Almost all API calls require an API Key so we add it to the parameters. |
||
135 | * |
||
136 | * @param $params |
||
137 | * @return string |
||
138 | */ |
||
139 | protected function prepareParams($method, $params) |
||
151 | |||
152 | /** |
||
153 | * Initialise or inject an instance of the Guzzle client. |
||
154 | * |
||
155 | * @return GuzzleClient |
||
156 | */ |
||
157 | protected function initGuzzleClient($guzzleClient = null) |
||
161 | |||
162 | /** |
||
163 | * Make the request to the XML Soccer service and validate response. |
||
164 | * |
||
165 | * @param string $uri |
||
166 | * @param array | null $params |
||
167 | * @throws RequestFailedException |
||
168 | * @return SimpleXMLElement |
||
169 | */ |
||
170 | protected function request($uri, $params) |
||
180 | } |
||
181 |