PHP Class Iamstuartwilson\StravaApi

Exibir arquivo Open project: iamstuartwilson/strava Class Usage Examples

Public Properties

Property Type Description
$lastRequest
$lastRequestData
$lastRequestInfo

Protected Properties

Property Type Description
$apiUrl
$authUrl
$clientId
$clientSecret
$responseHeaders array [ 'Cache-Control' => 'max-age=0, private, must-revalidate', 'X-RateLimit-Limit' => '600,30000', 'X-RateLimit-Usage' => '4,25', 'Content-Length' => '2031', ... ] Access with the getResponseHeader() or getResponseHeaders() methods.

Public Methods

Method Description
__construct ( integer $clientId = 1, string $clientSecret = '' ) Sets up the class with the $clientId and $clientSecret
authenticationUrl ( string $redirect, string $approvalPrompt = 'auto', string $scope = null, string $state = null ) : string Creates authentication URL for your app
deauthorize ( ) : string Deauthorises application
delete ( string $request, array $parameters = [] ) : string Sends DELETE request to specified API endpoint
get ( string $request, array $parameters = [] ) : string Sends GET request to specified API endpoint
getResponseHeader ( string $header ) : string
getResponseHeaders ( ) : array Returns the complete list of response headers.
post ( string $request, array $parameters = [] ) : string Sends POST request to specified API endpoint
put ( string $request, array $parameters = [] ) : string Sends PUT request to specified API endpoint
setAccessToken ( string $token ) : string Sets the access token used to authenticate API requests
tokenExchange ( string $code ) : string Authenticates token returned from API

Protected Methods

Method Description
generateParameters ( array $parameters ) : array Adds access token to paramters sent to API
parseGet ( string $url, array $query ) : string Appends query array onto URL
parseHeader ( resource $curl, string $headerLine ) : integer Parses the header lines into the $responseHeaders attribute
parseResponse ( string $response ) : object Parses JSON as PHP object
request ( string $url, array $parameters = [], boolean | string $request = false ) : mixed Makes HTTP Request to the API

Method Details

__construct() public method

Sets up the class with the $clientId and $clientSecret
public __construct ( integer $clientId = 1, string $clientSecret = '' )
$clientId integer
$clientSecret string

authenticationUrl() public method

Creates authentication URL for your app
public authenticationUrl ( string $redirect, string $approvalPrompt = 'auto', string $scope = null, string $state = null ) : string
$redirect string
$approvalPrompt string
$scope string
$state string
return string

deauthorize() public method

Deauthorises application
public deauthorize ( ) : string
return string

delete() public method

Sends DELETE request to specified API endpoint
public delete ( string $request, array $parameters = [] ) : string
$request string
$parameters array
return string

generateParameters() protected method

Adds access token to paramters sent to API
protected generateParameters ( array $parameters ) : array
$parameters array
return array

get() public method

Sends GET request to specified API endpoint
public get ( string $request, array $parameters = [] ) : string
$request string
$parameters array
return string

getResponseHeader() public method

public getResponseHeader ( string $header ) : string
$header string
return string

getResponseHeaders() public method

Returns the complete list of response headers.
public getResponseHeaders ( ) : array
return array

parseGet() protected method

Appends query array onto URL
protected parseGet ( string $url, array $query ) : string
$url string
$query array
return string

parseHeader() protected method

Skips the first header line (HTTP response status) and the last header line (empty).
protected parseHeader ( resource $curl, string $headerLine ) : integer
$curl resource
$headerLine string
return integer length of the currently parsed header line in bytes

parseResponse() protected method

Parses JSON as PHP object
protected parseResponse ( string $response ) : object
$response string
return object

post() public method

Sends POST request to specified API endpoint
public post ( string $request, array $parameters = [] ) : string
$request string
$parameters array
return string

put() public method

Sends PUT request to specified API endpoint
public put ( string $request, array $parameters = [] ) : string
$request string
$parameters array
return string

request() protected method

Makes HTTP Request to the API
protected request ( string $url, array $parameters = [], boolean | string $request = false ) : mixed
$url string
$parameters array
$request boolean | string the request method, default is POST
return mixed

setAccessToken() public method

Sets the access token used to authenticate API requests
public setAccessToken ( string $token ) : string
$token string
return string

tokenExchange() public method

Authenticates token returned from API
public tokenExchange ( string $code ) : string
$code string
return string

Property Details

$apiUrl protected_oe property

protected $apiUrl

$authUrl protected_oe property

protected $authUrl

$clientId protected_oe property

protected $clientId

$clientSecret protected_oe property

protected $clientSecret

$lastRequest public_oe property

public $lastRequest

$lastRequestData public_oe property

public $lastRequestData

$lastRequestInfo public_oe property

public $lastRequestInfo

$responseHeaders protected_oe property

[ 'Cache-Control' => 'max-age=0, private, must-revalidate', 'X-RateLimit-Limit' => '600,30000', 'X-RateLimit-Usage' => '4,25', 'Content-Length' => '2031', ... ] Access with the getResponseHeader() or getResponseHeaders() methods.
protected array $responseHeaders
return array