1 | <?php |
||
15 | abstract class Client implements LoggerAwareInterface |
||
16 | { |
||
17 | const BASE_URL = 'http://api.snd.no'; |
||
18 | |||
19 | /** |
||
20 | * @var GuzzleHttpClient |
||
21 | */ |
||
22 | protected $client; |
||
23 | |||
24 | /** |
||
25 | * @var string |
||
26 | */ |
||
27 | protected $apiKey; |
||
28 | |||
29 | /** |
||
30 | * @var string |
||
31 | */ |
||
32 | protected $apiSecret; |
||
33 | |||
34 | /** |
||
35 | * @var string |
||
36 | */ |
||
37 | protected $publicationId; |
||
38 | |||
39 | /** |
||
40 | * @var string |
||
41 | */ |
||
42 | protected $apiUrl = self::BASE_URL; |
||
43 | |||
44 | /** |
||
45 | * @var LoggerInterface |
||
46 | */ |
||
47 | protected $logger; |
||
48 | |||
49 | /** |
||
50 | * @param string $apiKey |
||
51 | * @param string $apiSecret |
||
52 | * @param string $publicationId |
||
53 | * @param string $apiUrl |
||
54 | */ |
||
55 | public function __construct($apiKey, $apiSecret, $publicationId, $apiUrl = self::BASE_URL) |
||
64 | |||
65 | /** |
||
66 | * @param RequestInterface $request |
||
67 | */ |
||
68 | protected function signRequest(RequestInterface $request) |
||
79 | |||
80 | /** |
||
81 | * @param RequestInterface $request |
||
82 | * @param bool $acceptJsonResponse |
||
83 | */ |
||
84 | protected function buildRequest(RequestInterface $request, $acceptJsonResponse = true) |
||
91 | |||
92 | /** |
||
93 | * @param string $url |
||
94 | * @param bool $acceptJsonResponse |
||
95 | * |
||
96 | * @return ResponseInterface |
||
97 | * @throws RequestException |
||
98 | */ |
||
99 | protected function apiGet($url, $acceptJsonResponse = true) |
||
113 | |||
114 | /** |
||
115 | * @return string |
||
116 | */ |
||
117 | public function getApiKey() |
||
121 | |||
122 | /** |
||
123 | * @param string $apiKey |
||
124 | */ |
||
125 | public function setApiKey($apiKey) |
||
129 | |||
130 | /** |
||
131 | * @return string |
||
132 | */ |
||
133 | public function getApiSecret() |
||
137 | |||
138 | /** |
||
139 | * @param string $apiSecret |
||
140 | */ |
||
141 | public function setApiSecret($apiSecret) |
||
145 | |||
146 | /** |
||
147 | * @return string |
||
148 | */ |
||
149 | public function getApiUrl() |
||
153 | |||
154 | /** |
||
155 | * @return string |
||
156 | */ |
||
157 | public function getPublicationId() |
||
161 | |||
162 | /** |
||
163 | * @param string $publicationId |
||
164 | * |
||
165 | * @throws InvalidPublicationIdException |
||
166 | * @SuppressWarnings(PHPMD.LongVariable) |
||
167 | */ |
||
168 | public function setPublicationId($publicationId) |
||
178 | |||
179 | /** |
||
180 | * Sets a logger instance on the object |
||
181 | * |
||
182 | * @param LoggerInterface $logger |
||
183 | * @return null |
||
184 | */ |
||
185 | public function setLogger(LoggerInterface $logger) |
||
189 | |||
190 | /** |
||
191 | * @param GuzzleHttpClient $client |
||
192 | */ |
||
193 | public function setClient(GuzzleHttpClient $client) |
||
197 | } |
||
198 |