Skip to content

Commit

Permalink
Return a Response object from client instead of stdClass
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanwinchester committed Oct 17, 2015
1 parent 5e823bc commit 3322c28
Show file tree
Hide file tree
Showing 5 changed files with 360 additions and 108 deletions.
22 changes: 21 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,14 @@ $data = $hubspot->contacts()->all([
'property' => ['firstname', 'lastname'],
'vidOffset' => 123456,
]);
```

Working with the data is easy!

```php
foreach ($data->contacts as $contact) {
echo sprintf(
"Contact name is %s %s.",
"Contact name is %s %s." . PHP_EOL,
$contact->properties->firstname->value,
$contact->properties->lastname->value
);
Expand All @@ -64,6 +68,22 @@ echo $data->{'has-more'};
echo $data->{'vid-offset'};
```

or if you prefer to use array access?

```php
foreach ($data['contacts'] as $contact) {
echo sprintf(
"Contact name is %s %s." . PHP_EOL,
$contact['properties']['firstname']['value'],
$contact['properties']['lastname']['value']
);
}

// Info for pagination
echo $data['has-more'];
echo $data['vid-offset'];
```

## Status

(:ballot_box_with_check: Complete, :wavy_dash: In Progress, :white_medium_small_square: Todo, :black_medium_small_square: Not planned)
Expand Down
59 changes: 0 additions & 59 deletions src/Contracts/ApiResponse.php

This file was deleted.

24 changes: 4 additions & 20 deletions src/Http/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,7 @@ public function __construct(GuzzleClient $client = null)
*/
public function get($url, array $options = [])
{
$contents = $this->client->request('GET', $url, $options)
->getBody()
->getContents();

return json_decode($contents);
return new Response($this->client->request('GET', $url, $options));
}

/**
Expand All @@ -44,11 +40,7 @@ public function get($url, array $options = [])
*/
public function post($url, array $options = [])
{
$contents = $this->client->request('POST', $url, $options)
->getBody()
->getContents();

return json_decode($contents);
return new Response($this->client->request('POST', $url, $options));
}

/**
Expand All @@ -58,11 +50,7 @@ public function post($url, array $options = [])
*/
public function put($url, array $options = [])
{
$contents = $this->client->request('PUT', $url, $options)
->getBody()
->getContents();

return json_decode($contents);
return new Response($this->client->request('PUT', $url, $options));
}

/**
Expand All @@ -72,10 +60,6 @@ public function put($url, array $options = [])
*/
public function delete($url, array $options = [])
{
$contents = $this->client->request('DELETE', $url, $options)
->getBody()
->getContents();

return json_decode($contents);
return new Response($this->client->request('DELETE', $url, $options));
}
}

0 comments on commit 3322c28

Please sign in to comment.