PHP Class App\services\RESTfulService

Show file Open project: phanan/koel Class Usage Examples

Protected Properties

Property Type Description
$client Client; The GuzzleHttp client to talk to the API.
$endpoint string The API endpoint.
$key string The API key.
$keyParam string For example, Last.fm use api_key, like this: https://ws.audioscrobbler.com/2.0?method=artist.getInfo&artist=Kamelot&api_key=API_KEY.
$responseFormat
$secret string The API secret.

Public Methods

Method Description
__call ( string $method, array $args ) : object Make an HTTP call to the external resource.
__construct ( $key, $secret, $endpoint, Client $client )
buildUrl ( string $uri, boolean $appendKey = true ) : string Turn a URI segment into a full API URL.
getClient ( ) : Client
getEndpoint ( ) : string
getKey ( ) : string
getSecret ( ) : string
request ( string $verb, string $uri, boolean $appendKey = true, array $params = [] ) : object | string Make a request to the API.
setClient ( Client $client )
setEndpoint ( string $endpoint )
setKey ( string $key )
setSecret ( string $secret )

Method Details

__call() public method

Make an HTTP call to the external resource.
public __call ( string $method, array $args ) : object
$method string The HTTP method
$args array An array of parameters
return object

__construct() public method

public __construct ( $key, $secret, $endpoint, Client $client )
$client GuzzleHttp\Client

buildUrl() public method

Turn a URI segment into a full API URL.
public buildUrl ( string $uri, boolean $appendKey = true ) : string
$uri string
$appendKey boolean Whether to automatically append the API key into the URL.
return string

getClient() public method

public getClient ( ) : Client
return GuzzleHttp\Client

getEndpoint() public method

public getEndpoint ( ) : string
return string

getKey() public method

public getKey ( ) : string
return string

getSecret() public method

public getSecret ( ) : string
return string

request() public method

Make a request to the API.
public request ( string $verb, string $uri, boolean $appendKey = true, array $params = [] ) : object | string
$verb string The HTTP verb
$uri string The API URI (segment)
$appendKey boolean Whether to automatically append the API key into the URI. While it's usually the case, some services (like Last.fm) requires an "API signature" of the request. Appending an API key will break the request.
$params array An array of parameters
return object | string

setClient() public method

public setClient ( Client $client )
$client GuzzleHttp\Client

setEndpoint() public method

public setEndpoint ( string $endpoint )
$endpoint string

setKey() public method

public setKey ( string $key )
$key string

setSecret() public method

public setSecret ( string $secret )
$secret string

Property Details

$client protected property

The GuzzleHttp client to talk to the API.
protected Client; $client
return Client;

$endpoint protected property

The API endpoint.
protected string $endpoint
return string

$key protected property

The API key.
protected string $key
return string

$keyParam protected property

For example, Last.fm use api_key, like this: https://ws.audioscrobbler.com/2.0?method=artist.getInfo&artist=Kamelot&api_key=API_KEY.
protected string $keyParam
return string

$responseFormat protected property

protected $responseFormat

$secret protected property

The API secret.
protected string $secret
return string