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
Requires
- guzzlehttp/guzzle: 5.2.0
- guzzlehttp/guzzle-services: 0.5.0
Requires (Dev)
- phpunit/phpunit: 4.5.*
README
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'];