PHP code example of bbc / ipr-webservicekit

1. Go to this page and download the library: Download bbc/ipr-webservicekit library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

bbc / ipr-webservicekit example snippets


$client = new GuzzleHttp\Client();
$cache = new BBC\iPlayerRadio\Cache\Cache(new RedisCache());

$service = new BBC\iPlayerRadio\WebserviceKit\Service(
    $client,
    $cache
);



use BBC\iPlayerRadio\WebserviceKit\Query;

class MyBackendQuery extends Query
{
    /**
     * Returns the URL to query, with any parameters applied.
     *
     * @return  string
     */
    public function getURL()
    {
        return 'http://my.service:8080/';
    }

    /**
     * Returns a friendly (and safe) name of the webservice this query hits which we can use in
     * error logging and circuit breakers etc. [a-z0-9-_] please.
     *
     * @return  string
     */
    public function getServiceName()
    {
        return 'my.service';
    }

    /**
     * Given a response from the webservice, this function is called to transform it into something
     * a bit more useful for output.
     *
     * This may be passed a false or a null if the call to the webservice fails, so unit test appropriately.
     *
     * @param   mixed   $response
     * @param   array   $headers
     * @return  mixed
     */
    public function transformPayload($response, array $headers)
    {
        $this->lastHeaders = $headers;
        return $response ? json_decode($response) : $response;
    }
}


$response = $service->fetch($query);

list($response1, $response2) = $service->fetch([$query1, $query2]);