core23/setlistfm-api

0.2.0 2017-07-23 08:03 UTC

README

Latest Stable Version Latest Unstable Version License

Build Status Scrutinizer Code Quality Code Climate Coverage Status SensioLabsInsight

Donate to this project using Flattr Donate to this project using PayPal

This library provides a wrapper for using the Setlist.fm API inside PHP and a bridge for symfony.

Installation

php composer.phar require core23/setlistfm-api

php composer.phar require guzzlehttp/guzzle # if you want to use Guzzle native
php composer.phar require php-http/guzzle6-adapter # if you want to use HTTPlug with Guzzle

General usage

    // Get HTTPlug client and message factory
    $client         = \Http\Discovery\HttpClientDiscovery::find();
    $messageFactory = \Http\Discovery\MessageFactoryDiscovery::find();

    // Create connection
    $connection = new \Core23\SetlistFm\Connection\HTTPlugConnection($client, $messageFactory);

    $artistApi = new \Core23\SetlistFm\Service\ArtistService($connection);
    $artists = $artistApi->search(array(
        'artistName' => 'Slipknot'
    ));

Symfony usage

Enabling the bundle

    // app/AppKernel.php

    public function registerBundles()
    {
        return array(
            // ...
            
            new Http\HttplugBundle\HttplugBundle(),
            new Core23\SetlistFm\Bridge\Symfony\Bundle\Core23SetlistFmBundle(),

            // ...
        );
    }

Define the API credentials in your configuration.

    # config.yml

    core23_setlist_fm:
        api:
            key:    %setlistfm_api.key%

Define a HTTPlug client in your configuration.

    # config.yml
    
    httplug:
        classes:
            client: Http\Adapter\Guzzle6\Client
            message_factory: Http\Message\MessageFactory\GuzzleMessageFactory
            uri_factory: Http\Message\UriFactory\GuzzleUriFactory
            stream_factory: Http\Message\StreamFactory\GuzzleStreamFactory

It is recommended to use a cache to reduce the API usage.

    httplug:
        plugins:
            cache:
                cache_pool: 'acme.httplug_cache'
                config:
                    default_ttl: 7200 # Two hours
        clients:
            default:
                plugins:
                    - httplug.plugin.cache

This lib / bundle is available under the MIT license.