Skip to content

Instantly share code, notes, and snippets.

@pschultz
Created October 29, 2013 12:48
Show Gist options
  • Save pschultz/7214036 to your computer and use it in GitHub Desktop.
Save pschultz/7214036 to your computer and use it in GitHub Desktop.
guzzle responseClass example
<?php
namespace Classmarkets\Api;
use Guzzle\Service\Command\OperationCommand;
class ItemCollection extends \Doctrine\Common\Collections\ArrayCollection
{
// This is the method Guzzle is looking for
public static function fromCommand(OperationCommand $command)
{
$response = $command->getResponse();
$data = $response->json(); // if you are not receiving json, there is a way of getting the raw response. Check the docs
return self::fromArray($data);
}
public static function fromArray(array $data)
{
$collection = new self();
// assign $collection's with values in $data
return $collection
}
}
name: Item
operations:
Search:
httpMethod: GET
uri: /search
responseClass: Classmarkets\Api\ItemCollection
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment