I have the following service description that I had used for quite a while with older version of Guzzle:
[ 'name' => 'Gist', 'apiVersion' => 'v3', 'baseUrl' => 'https://api.github.com/', 'description' => 'Gists and comments access', 'operations' => [ 'GetGists' => [ 'httpMethod' => 'GET', 'uri' => '/users/{user}/gists', 'parameters' => [ 'user' => [ 'location' => 'uri', 'required' => true, ], 'since' => [ 'location' => 'query', ], ], ], 'GetComments' => [ 'httpMethod' => 'GET', 'uri' => '/gists/{id}/comments', 'parameters' => [ 'id' => [ 'location' => 'uri', 'required' => true, ], ], ], ], ]
Now I am moving bunch of thing to a current version of Guzzle and this absolutely refuses to work with newer broken out guzzle/services
.
My code is along the lines of:
$client = new Client; $client->setDefaultOption('verify', false); $description = new Description($this->getServiceDescription()); $guzzleClient = new GuzzleClient($client, $description); $command = $guzzleClient->getCommand('GetGists', [ 'user' => $this->user ]); $gists = $guzzleClient->execute($command); // $gists is empty array?..
It clearly understands command at least partially, since it will complain if I don’t provide required argument or misspell name.
But in the end it’s just empty array and no remote idea what I need to do to troubleshoot it or how do I need to update service description.
The URL it should (does?) access is https://api.github.com/users/Rarst/gists
Advertisement
Answer
Ok, it seems that model is mandatory to interpret response and I got it to working (without much understanding of what and how model controls : ):
[ 'name' => 'Gist', 'apiVersion' => 'v3', 'baseUrl' => 'https://api.github.com/', 'description' => 'Gists and comments access', 'operations' => [ 'GetGists' => [ 'responseModel' => 'getResponse', 'httpMethod' => 'GET', 'uri' => '/users/{user}/gists', 'parameters' => [ 'user' => [ 'location' => 'uri', 'required' => true, ], 'since' => [ 'location' => 'query', ], ], ], 'GetComments' => [ 'responseModel' => 'getResponse', 'httpMethod' => 'GET', 'uri' => '/gists/{id}/comments', 'parameters' => [ 'id' => [ 'location' => 'uri', 'required' => true, ], ], ], ], 'models' => [ 'getResponse' => [ 'type' => 'object', 'additionalProperties' => [ 'location' => 'json' ] ] ] ]