Created
September 30, 2019 09:14
-
-
Save devops-school/07ce43cbca8f80606ae47b1d2ffa843b to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
use GuzzleHttp\Exception\GuzzleException; | |
use GuzzleHttp\Exception\RequestException; | |
use GuzzleHttp\Client; | |
public static function getTestApiRespone(string $access_token) { | |
try { | |
$http = new Client(); //GuzzleHttp\Client | |
$response = $http->get( | |
'http://surgery-planet-quote-booking/api/test', | |
[ | |
'headers' => [ | |
'Accept' => 'html', | |
'Authorization' => 'Bearer ' . $access_token | |
] | |
] | |
); | |
return $response->getBody(); | |
} catch (RequestException $e) { | |
/*Debugbar::error('Inside Helper->getQuoteBookingForm()->CATCH BLOCK'); | |
Debugbar::error($e); | |
Debugbar::error($e->getMessage()); | |
Debugbar::error('Exiting from Helper->getQuoteBookingForm()->CATCH BLOCK');*/ | |
return $e->getResponse()->getStatusCode() . ': ' . $e->getMessage(); | |
} | |
} | |
public static function getTestApiResponeWithAuth() { | |
try { | |
$http = new Client(); //GuzzleHttp\Client | |
$response = $http->post( | |
'http://surgery-planet-quote-booking/oauth/token', | |
[ | |
'form_params' => [ | |
'grant_type' => 'client_credentials', | |
'client_id' => '6', | |
'client_secret' => 'YoaLmACopaMUTZsmB4fsxtn6OEMGQj7FqZsbazwQ', | |
'redirect_uri' => '', | |
], | |
] | |
); | |
$array = $response->getBody()->getContents(); | |
$json = json_decode($array, true); | |
$collection = collect($json); | |
$access_token = $collection->get('access_token'); | |
return Helper::getTestApiRespone($access_token); | |
} catch (RequestException $e) { | |
/*Debugbar::error('Inside Helper->getQuoteBookingFormWithAuth()->CATCH BLOCK'); | |
Debugbar::error($e); | |
Debugbar::error($e->getMessage()); | |
Debugbar::error('Exiting from Helper->getQuoteBookingFormWithAuth()->CATCH BLOCK');*/ | |
return $e->getResponse()->getStatusCode() . ': ' . $e->getMessage(); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment