Skip to content

Commit

Permalink
Adds IntegrationsClient
Browse files Browse the repository at this point in the history
  • Loading branch information
andrelopez committed Apr 8, 2021
1 parent 756d963 commit c0a8a9a
Showing 1 changed file with 45 additions and 0 deletions.
45 changes: 45 additions & 0 deletions src/Integration/IntegrationsClient.php
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;
}
}

0 comments on commit c0a8a9a

Please sign in to comment.