1 | <?php |
||
14 | abstract class Api |
||
15 | { |
||
16 | public $apikey; |
||
17 | |||
18 | /** |
||
19 | * @var bool If Response is json format, Default is true, will decode to array. |
||
20 | */ |
||
21 | protected $isJsonResponse = true; |
||
22 | |||
23 | /** |
||
24 | * {@inheritdoc} |
||
25 | * |
||
26 | * @param string $apikey Api key |
||
27 | */ |
||
28 | 17 | public function __construct($apikey) |
|
32 | |||
33 | /** |
||
34 | * Fetch result. |
||
35 | * |
||
36 | * @param mixed $params |
||
37 | * |
||
38 | * @return mixed |
||
39 | */ |
||
40 | abstract public function get($params); |
||
41 | |||
42 | /** |
||
43 | * 准备请求头. |
||
44 | * |
||
45 | * @return array 默认的请头 |
||
46 | */ |
||
47 | 16 | protected function prepareHeaders() |
|
53 | |||
54 | /** |
||
55 | * Fetch result by $address. |
||
56 | * |
||
57 | * @param string $address |
||
58 | * |
||
59 | * @return mixed |
||
60 | */ |
||
61 | 16 | public function fetch($address) |
|
83 | |||
84 | /** |
||
85 | * Parse response to array. |
||
86 | * |
||
87 | * @param mixed $result |
||
88 | * |
||
89 | * @return array |
||
90 | */ |
||
91 | 11 | protected function _parseResponse($result) |
|
110 | } |
||
111 |