itkg / consumer
Itkg consume library
Installs: 27 897
Dependents: 1
Suggesters: 0
Security: 0
Stars: 2
Watchers: 29
Forks: 5
Open Issues: 1
Requires
- php: >=5.3.3
- fkooman/guzzle-bearer-auth-plugin: 0.2.*
- fkooman/oauth-client: 0.5.*
- guzzle/guzzle: ~3
- itkg/core: ~1
- jms/serializer: *
- symfony/options-resolver: ~2
Requires (Dev)
- phpunit/phpunit: 3.7.*
This package is not auto-updated.
Last update: 2024-11-15 22:24:51 UTC
README
features
- Rest & Soap consumer library
- Webservice caching
- Logging
- OAuth management
Installation
Installation by Composer
If you use composer, add library as a dependency to the composer.json of your application
"require": { "itkg/consumer": "dev-master" }
Usage
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();
Configuration
Logs
- 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());
Serialization
- 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();
Cache
- 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