PHP Class SpotifyWebAPI\Request

Mostra file Open project: jwilsson/spotify-web-api-php Class Usage Examples

Protected Properties

Property Type Description
$returnAssoc

Public Methods

Method Description
account ( string $method, string $uri, array $parameters = [], array $headers = [] ) : array Make a request to the "account" endpoint.
api ( string $method, string $uri, array $parameters = [], array $headers = [] ) : array Make a request to the "api" endpoint.
getReturnAssoc ( ) : boolean Get a value indicating the response body type.
send ( string $method, string $url, array $parameters = [], array $headers = [] ) : array Make a request to Spotify.
setReturnAssoc ( boolean $returnAssoc ) : void Set the return type for the response body.

Protected Methods

Method Description
parseBody ( string $body, integer $status ) : array | object Parse the response body and handle API errors.
parseHeaders ( string $headers ) : array Parse HTTP response headers.

Method Details

account() public method

Make a request to the "account" endpoint.
public account ( string $method, string $uri, array $parameters = [], array $headers = [] ) : array
$method string The HTTP method to use.
$uri string The URI to request.
$parameters array Optional. Query parameters.
$headers array Optional. HTTP headers.
return array Response data. - array|object body The response body. Type is controlled by Request::setReturnAssoc(). - string headers Response headers. - int status HTTP status code. - string url The requested URL.

api() public method

Make a request to the "api" endpoint.
public api ( string $method, string $uri, array $parameters = [], array $headers = [] ) : array
$method string The HTTP method to use.
$uri string The URI to request.
$parameters array Optional. Query parameters.
$headers array Optional. HTTP headers.
return array Response data. - array|object body The response body. Type is controlled by Request::setReturnAssoc(). - string headers Response headers. - int status HTTP status code. - string url The requested URL.

getReturnAssoc() public method

Get a value indicating the response body type.
public getReturnAssoc ( ) : boolean
return boolean Whether the body is returned as an associative array or an stdClass.

parseBody() protected method

Parse the response body and handle API errors.
protected parseBody ( string $body, integer $status ) : array | object
$body string The raw, unparsed response body.
$status integer The HTTP status code, used to see if additional error handling is needed.
return array | object The parsed response body. Type is controlled by Request::setReturnAssoc().

parseHeaders() protected method

Parse HTTP response headers.
protected parseHeaders ( string $headers ) : array
$headers string The raw, unparsed response headers.
return array Headers as key–value pairs.

send() public method

You'll probably want to use one of the convenience methods instead.
public send ( string $method, string $url, array $parameters = [], array $headers = [] ) : array
$method string The HTTP method to use.
$url string The URL to request.
$parameters array Optional. Query parameters.
$headers array Optional. HTTP headers.
return array Response data. - array|object body The response body. Type is controlled by Request::setReturnAssoc(). - array headers Response headers. - int status HTTP status code. - string url The requested URL.

setReturnAssoc() public method

Set the return type for the response body.
public setReturnAssoc ( boolean $returnAssoc ) : void
$returnAssoc boolean Whether to return an associative array or an stdClass.
return void

Property Details

$returnAssoc protected_oe property

protected $returnAssoc