- Rest & Soap consumer library
- Webservice caching
- Logging
- OAuth management
If you use composer, add library as a dependency to the composer.json of your application
"require": {
"itkg/consumer": "dev-master"
}
Simple example of Rest WS
$service = new \Itkg\Consumer\Service\Service(
$eventDispatcher,
new Itkg\Consumer\Client\RestClient(array(
'timeout' => 10
)),
array(
'identifier' => 'my test'
)
);
$response = $service
->sendRequest(\Symfony\Component\HttpFoundation\Request::create('http://URL/OF/MY/WEBSERVICE.json'))
->getResponse();
- Create a new logger instance
$service = new \Itkg\Consumer\Service\Service(
$eventDispatcher,
new Itkg\Consumer\Client\RestClient(array(
'timeout' => 10
)),
array(
'identifier' => 'my test',
'logger' => new \Monolog\Logger('my_logger', array(new \Monolog\Handler\StreamHandler('/tmp/test'))),
)
);
- Add logger listener to your event dispatcher
$eventDispatcher->addSubscriber(new \Itkg\Consumer\Listener\LoggerListener());
- Add Deseralizer listener to your event dispatcher (Create serializer with JMS serializer builder)
$eventDispatcher->addSubscriber(
new \Itkg\Consumer\Listener\DeserializerListener(JMS\Serializer\SerializerBuilder::create()->build())
);
- Define response_type & response_format
$service = new \Itkg\Consumer\Service\Service(
$eventDispatcher,
new Itkg\Consumer\Client\RestClient(array(
'timeout' => 10
)),
array(
'identifier' => 'my test',
'reponse_format' => 'xml,
'response_type' => 'My\Class
)
);
- Get deserialized content like this
$object = $service->getResponse()->getDeserializedContent();
- Add Cache listener to your event dispatcher
$eventDispatcher->addSubscriber(
new \Itkg\Consumer\Listener\CacheListener($eventDispatcher)
);
- Add cache adapter to your service (see : https://github.com/itkg/core for adapters list)
$service = new \Itkg\Consumer\Service\Service(
$eventDispatcher,
new Itkg\Consumer\Client\RestClient(array(
'timeout' => 10
)),
array(
'identifier' => 'my test',
'cache_adapter' => new \Itkg\Core\Cache\Adapter\Registry(),
'cache_ttl => 10000
)
);
- You can define serialize & deserialize method by defining 'cache_serializer' & 'cache_deserializer' options