我有以下服务说明,我使用旧版本的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,
],
],
],
],
]
现在我正在将一堆东西移到当前版本的Guzzle中,这绝对不适用于更新的guzzle/services
。
我的代码如下:
$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?..
显然至少部分理解命令,因为如果我不提供必需的参数或拼写错误的名称,它会抱怨。
但最后它只是空数组,没有远程想法我需要做什么来解决它或我如何更新服务描述。
它应该(确实?)访问的网址是https://api.github.com/users/Rarst/gists
答案 0 :(得分:2)
好的,似乎模型是强制解释响应的,我让它工作(没有太多了解模型控制的内容和方式:\):
[
'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'
]
]
]
]