4242 */
4343abstract class ApiAbstract
4444{
45- /** @var \Zend_Rest_Client */
45+ /** @var \GuzzleHttp\Client */
4646 protected $ restClient ;
4747
4848 /**
@@ -186,14 +186,12 @@ protected function _request($route, $params = [])
186186 }
187187
188188 $ client = $ this ->getRestClient ();
189- $ client ->getHttpClient ()->resetParameters ();
190- $ this ->_applyAuth ($ client );
191189
192- $ response = $ client ->restGet ($ route , $ params );
193- $ responseBody = $ response ->getBody ();
190+ $ response = $ client ->get ($ route , [ ' query ' => $ params] );
191+ $ responseBody = ( string ) $ response ->getBody ();
194192
195- if ($ response ->getStatus () !== 200 ) {
196- throw new ApiException ($ responseBody , $ response ->getStatus ());
193+ if ($ response ->getStatusCode () !== 200 ) {
194+ throw new ApiException ($ responseBody , $ response ->getStatusCode ());
197195 }
198196
199197 $ this ->cache ->save (serialize ($ response ), $ cacheKey , [], 3600 * 24 );
@@ -210,33 +208,27 @@ protected function _getCacheKey($route, $params)
210208 }
211209
212210 /**
213- * @return \Zend_Rest_Client
211+ * @return \GuzzleHttp\Client
214212 */
215213 public function getRestClient ()
216214 {
217215 if (!$ this ->restClient ) {
218- $ client = $ this ->restClientFactory ->create ();
219- $ httpClient = $ client ->getHttpClient ();
220- $ httpClient ->setHeaders (array ('Content-Type: application/json ' ));
221- $ httpClient ->setConfig (array (
222- 'keepalive ' => true ,
223- 'timeout ' => 10 ,
224- ));
225- $ client ->setUri ($ this ->getBaseUri ());
216+
217+ $ client = new \GuzzleHttp \Client ([
218+ 'base_uri ' => $ this ->getBaseUri (),
219+ 'timeout ' => 10 ,
220+ 'defaults ' => [
221+ 'headers ' => ['Content-Type ' => 'application/json ' ],
222+ 'auth ' => [
223+ $ this ->scopeConfig ->getValue ('skywire_wordpress_api/api/username ' , ScopeInterface::SCOPE_STORE ),
224+ $ this ->scopeConfig ->getValue ('skywire_wordpress_api/api/password ' , ScopeInterface::SCOPE_STORE )
225+ ],
226+ ]
227+ ]);
226228
227229 $ this ->restClient = $ client ;
228230 }
229231
230232 return $ this ->restClient ;
231233 }
232-
233- protected function _applyAuth (\Zend_Rest_Client $ client )
234- {
235- $ username = $ this ->scopeConfig ->getValue ('skywire_wordpress_api/api/username ' , ScopeInterface::SCOPE_STORE );
236- $ password = $ this ->scopeConfig ->getValue ('skywire_wordpress_api/api/password ' , ScopeInterface::SCOPE_STORE );
237-
238- if ($ username && $ password ) {
239- $ client ->getHttpClient ()->setAuth ($ username , $ password );
240- }
241- }
242234}
0 commit comments