-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
c863c18
commit 61081eb
Showing
4 changed files
with
95 additions
and
35 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
<?php | ||
|
||
namespace DigitaloceanApi\Services; | ||
|
||
use GuzzleHttp\Client; | ||
|
||
class SendRequestService | ||
{ | ||
/** | ||
* @var $client | ||
*/ | ||
protected $client; | ||
|
||
public function __construct() | ||
{ | ||
$this->client = new Client([ | ||
'headers' => [ | ||
'Content-Type' => 'application/json', | ||
'Authorization' => 'Bearer '. config('digital-ocean.token'), | ||
]]); | ||
} | ||
|
||
/** | ||
* @param $method | ||
* @param $uri | ||
* @param $params | ||
* | ||
* @return mixed|\stdClass | ||
* | ||
* @throws \GuzzleHttp\Exception\GuzzleException | ||
*/ | ||
public function send($method, $uri, $params = []) | ||
{ | ||
try { | ||
$res = $this->client->request($method, $uri, $params); | ||
|
||
if($method !== 'DELETE') { | ||
$response = \json_decode($res->getBody()); | ||
$response->status_code = $res->getStatusCode(); | ||
|
||
return $response; | ||
} | ||
$response = new \stdClass(); | ||
$response->status_code = $res->getStatusCode(); | ||
|
||
return $response; | ||
|
||
} catch (\GuzzleHttp\Exception\RequestException $exception) { | ||
$error = \json_decode($exception->getResponse()->getBody()); | ||
$error->status_code = $exception->getResponse()->getStatusCode(); | ||
|
||
return $error; | ||
} | ||
} | ||
} |
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
* | ||
!.gitignore |