1 | <?php |
||
7 | abstract class MethodPluginBase implements MethodPluginInterface { |
||
8 | |||
9 | /** |
||
10 | * The method name. |
||
11 | */ |
||
12 | const METHOD = 'BASE'; |
||
13 | |||
14 | /** |
||
15 | * The parameters. |
||
16 | * |
||
17 | * @var array |
||
18 | */ |
||
19 | protected $parameters; |
||
20 | |||
21 | /** |
||
22 | * The API Key. |
||
23 | * |
||
24 | * @var string |
||
25 | */ |
||
26 | protected $apiKey; |
||
27 | |||
28 | /** |
||
29 | * The API Version. |
||
30 | * |
||
31 | * @var int |
||
32 | */ |
||
33 | protected $apiVersion; |
||
34 | |||
35 | /** |
||
36 | * {@inheritdoc} |
||
37 | */ |
||
38 | 25 | public function getMethod() { |
|
41 | |||
42 | /** |
||
43 | * {@inheritdoc} |
||
44 | */ |
||
45 | 25 | public function setParameters(array $parameters = array()) { |
|
50 | |||
51 | /** |
||
52 | * {@inheritdoc} |
||
53 | */ |
||
54 | 13 | public function getDefaultParameters() { |
|
57 | |||
58 | /** |
||
59 | * {@inheritdoc} |
||
60 | */ |
||
61 | 25 | public function getParameters() { |
|
90 | |||
91 | /** |
||
92 | * Get a random ID. |
||
93 | * |
||
94 | * @return string |
||
95 | */ |
||
96 | 13 | public function getRandomId() { |
|
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | 13 | public function setApiVersion($apiVersion) { |
|
108 | |||
109 | /** |
||
110 | * {@inheritdoc} |
||
111 | */ |
||
112 | 13 | public function getApiVersion() { |
|
115 | |||
116 | /** |
||
117 | * {@inheritdoc} |
||
118 | */ |
||
119 | 13 | public function get(ResponseInterface $response, $key = NULL) { |
|
120 | 13 | if ($content = $this->getContent($response)) { |
|
121 | 13 | if (is_array($content)) { |
|
122 | 13 | if (!is_null($key) && isset($content[$key])) { |
|
123 | 13 | return $content[$key]; |
|
124 | } |
||
125 | 12 | if (is_null($key)) { |
|
126 | 12 | return $content; |
|
127 | } |
||
128 | } |
||
129 | } |
||
130 | |||
131 | 12 | return FALSE; |
|
132 | } |
||
133 | |||
134 | /** |
||
135 | * {@inheritdoc} |
||
136 | */ |
||
137 | 13 | public function getContent(ResponseInterface $response) { |
|
138 | 13 | $body = $response->getBody()->__toString(); |
|
139 | 13 | if (strpos($response->getHeaderLine('Content-Type'), 'application/json') === 0) { |
|
140 | 13 | $content = json_decode($body, true); |
|
141 | 13 | if (JSON_ERROR_NONE === json_last_error()) { |
|
142 | 13 | return $content; |
|
143 | } |
||
144 | } |
||
145 | |||
146 | return FALSE; |
||
147 | } |
||
148 | |||
149 | /** |
||
150 | * {@inheritdoc} |
||
151 | */ |
||
152 | public function getHeader(ResponseInterface $response, $name) { |
||
156 | |||
157 | } |
||
158 |