Skip to content

Commit

Permalink
Merge pull request #21 from andrelopez/master
Browse files Browse the repository at this point in the history
Adds IntegrationsClient
  • Loading branch information
tomrutherford-livestyled authored Apr 8, 2021
2 parents 9973a27 + c0a8a9a commit c92118c
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 c92118c

Please sign in to comment.