-
Notifications
You must be signed in to change notification settings - Fork 3
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
756d963
commit c0a8a9a
Showing
1 changed file
with
45 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace LiveStyled\Integration; | ||
|
||
use GuzzleHttp\Exception\BadResponseException; | ||
use LiveStyled\Client; | ||
use LiveStyled\CrudClient; | ||
use LiveStyled\Exception\EntityFetchException; | ||
|
||
class IntegrationsClient extends Client implements CrudClient | ||
{ | ||
protected function getPath() | ||
{ | ||
return '/v4/integration/integrations'; | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* @param array $payload | ||
* @return mixed | ||
* @throws EntityFetchException | ||
*/ | ||
public function runByType(string $type, array $payload) | ||
{ | ||
try { | ||
$response = $this->httpClient->post($this->getPathByType($type), [ | ||
'body' => json_encode($payload), | ||
'headers' => $this->getHeaders() | ||
]); | ||
} catch (BadResponseException $e) { | ||
throw new EntityFetchException($e->getMessage(), $e->getCode(), $e); | ||
} | ||
|
||
return json_decode($response->getBody()->getContents(), true); | ||
} | ||
|
||
/** | ||
* @param string $type | ||
* @return string | ||
*/ | ||
private function getPathByType(string $type) | ||
{ | ||
return $this->getPath().'/run_by_type/'.$type; | ||
} | ||
} |