misd-service-development / guzzle-bundle

[NOT MAINTAINED] Integrates Guzzle into your Symfony2 application
99 stars 54 forks source link

Class must exist and implement a static fromCommand() method #58

Closed IljaN closed 10 years ago

IljaN commented 10 years ago

I followed the documentation found here and injected Service definition in to my file but the result does not get unserialized.

I am getting the following error:

array<Acme\Bundle\TestBundle\Entity\Building> must exist and implement a static fromCommand() method

It looks as if the JMSSerializer is not loaded correctly. On a side note: I installed JMSSerializer after guzzle-bundle.

services.yml

  test.api.service_description:
        class: "%guzzle.service_description.class%"
        factory_class: "%guzzle.service_description.class%"
        factory_method: factory
        arguments:
            - "%test.api.service_description_file%"

    test.api.client:
        class: "%guzzle.client.class%"
        calls:
            - [setDescription, [@test.api.service_description]]
        tags:
            - {name: "guzzle.client"}

    test.sync_service:
        class: Acme\Bundle\TestBundle\Service\SyncService
        arguments: [@doctrine.orm.default_entity_manager, @test.api.client,%api_key%]

service description:

{
    "name": "Management Api",
    "baseUrl": "http://acme.de/management/api",
    "operations": {
        "GetBuildings":{
            "httpMethod":"GET",
            "uri":"building",
            "summary":"Gets buildings",
            "responseClass":"array<Acme\\Bundle\\TestBundle\\Entity\\Building>",
            "data": {
                "jms_serializer.groups": "result",
                "jms_serializer.version": 1,
                "jms_serializer.max_depth_checks": true

            },
            "parameters":{
                "token":{
                    "sentAs": "token",
                    "location":"query",
                    "type":"string",
                    "description":"API Key",
                    "required": true
                }
        }
    }
}

Call to service:

$command = $this->client->getCommand('GetBuildings',array(
            'token' => $this->apiKey
        ));
$this->client->execute($command);

Cheerz Ilja

IljaN commented 10 years ago

Okay forget it. The content type from the api response was not set to json thus falling back to other response parsers.