Skip to content

Commit

Permalink
Improve use of ApiResponse to return data
Browse files Browse the repository at this point in the history
  • Loading branch information
javier-villatoro committed Aug 6, 2024
1 parent aa6e06b commit 237728a
Showing 1 changed file with 18 additions and 20 deletions.
38 changes: 18 additions & 20 deletions src/Http/Client/LeverClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -80,48 +80,48 @@ private function sendRequest($method, $endpoint, array $options = []): ResponseI
}
}

public function get(): ResponseInterface
public function get(): array
{
return $this->sendRequest('GET', $this->endpoint, $this->options);
$response = $this->sendRequest('GET', $this->endpoint, $this->options);

return ApiResponse::using($response)->toArray();
}

public function post(array $body = []): ResponseInterface
public function post(array $body = []): array
{
return $this->sendRequest('POST', $this->endpoint, $this->prepareOptions($body));
$response = $this->sendRequest('POST', $this->endpoint, $this->prepareOptions($body));

return ApiResponse::using($response)->toArray();
}

public function put(array $body = []): ResponseInterface
public function put(array $body = []): array
{
return $this->sendRequest('PUT', $this->endpoint, $this->prepareOptions($body));
$response = $this->sendRequest('PUT', $this->endpoint, $this->prepareOptions($body));

return ApiResponse::using($response)->toArray();
}

public function create(array $body, string $method = 'post'): array
{
$response = ApiResponse::using($this->$method($body))->toArray();

return $response;
return $this->$method($body);
}

public function update(array $body): array
{
$response = ApiResponse::using($this->post($body))->toArray();

return $response;
return $this->post($body);
}

public function putUpdate(array $body): array
{
$response = ApiResponse::using($this->put($body))->toArray();

return $response;
return $this->put($body);
}

public function fetch(): LazyCollection|array
{
$endpoint = $this->endpoint;
$options = $this->options;

$response = ApiResponse::using($this->get())->toArray();
$response = $this->get();

if (! array_key_exists('hasNext', $response)) {
return $response['data'];
Expand All @@ -140,7 +140,7 @@ public function fetch(): LazyCollection|array
if (! empty($response['next'])) {
$this->options['query']['offset'] = json_decode(urldecode($response['next']));

$response = ApiResponse::using($this->get())->toArray();
$response = $this->get();
} else {
return;
}
Expand Down Expand Up @@ -292,9 +292,7 @@ public function apply(array $body = []): array
{
$this->endpoint .= '/apply';

$application = ApiResponse::using($this->post($body))->toArray();

return $application;
return $this->post($body);
}

public function notes(?string $noteId = null): self
Expand Down

0 comments on commit 237728a

Please sign in to comment.