2

我有以下服务描述,我在旧版本的 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 上,这绝对拒绝与更新的 break out 一起使用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?..

它至少部分清楚地理解命令,因为如果我不提供必需的参数或拼写错误的名称,它会抱怨。

但最终它只是一个空数组,不知道我需要做什么来解决它或我需要如何更新服务描述。

它应该(可以?)访问的 URL 是https://api.github.com/users/Rarst/gists

4

1 回答 1

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'
            ]
        ]
    ]
]
于 2014-12-11T22:48:22.120 回答