asgoodasnu/guzzlecommandclient

Guzzle Client for Symfony2

This package's canonical repository appears to be gone and the package has been frozen as a result.

Installs: 1 439

Dependents: 5

Suggesters: 0

Security: 0

Stars: 1

Watchers: 25

Forks: 1

Open Issues: 0

Type:symfony-bundle

v0.14 2015-02-13 12:53 UTC

This package is not auto-updated.

Last update: 2019-12-09 03:30:05 UTC


README

Composer Downloads Build Status Dependency Status Reference Status

This Symfony 2 bundle implements Guzzle Commands

https://github.com/guzzle/command

Installing

This project can be installed using Composer. Add the following to your composer.json:

{
    "require": {
        "asgoodasnu/guzzlecommandclient": "dev-master"
    }
}

Defining services

Create a json file defining the different operations available, for example:

{
    "name": "My Service name",
    "baseUrl": "",
    "operations": {
        "myOperationName": {
            "httpMethod": "GET",
            "uri": "/api/getProduct/{id}.{format}",
            "summary": "Retrieve all products",
            "responseClass": "MyModelResponse",
            "parameters": {
                "format": {
                    "default": "json",
                    "location": "uri"
                },
                "id": {
                    "type": "string",
                    "required": "true",
                    "location": "uri"
                }
            }
        }
    },
    "models": {
        "MyModelResponse": {
            "type": "object"
        }
    }
}

Using it

$json = file_get_contents(path/to/json/file");

$guzzleCommandClient = new GuzzleCommandClient($json);
$guzzleCommandClient->setBaseUrl($imageServiceEndpoint);

$params = array(
    'id' => '12345',
);

$result = $guzzleCommandClient->executeCommand('myOperationName', $params);

if ($result['status'] == 'error') {
    // Show the error 
    return;
}

if (is_object($result['message'])) {
    // Deal with the response object
    return $result['message']->json();
}

return $result['message'];