Giter Club home page Giter Club logo

consumer's Introduction

Webservice consumer library

Build Status Scrutinizer Code Quality Code Coverage SensioLabsInsight

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)
    );
$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

consumer's People

Contributors

betd-sthibault avatar itkg-abeauvain avatar itkg-ahidri avatar itkg-jbrousseau avatar jbrousseau avatar juchi avatar pdenis avatar scrutinizer-auto-fixer avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.