PHP Class ThreeScaleClient

Objects of this class are stateless and can be shared through multiple transactions and by multiple clients.
Show file Open project: 3scale/3scale_ws_api_for_php Class Usage Examples

Public Methods

Method Description
__construct ( $providerKey, $host = self::DEFAULT_HOST, $httpClient = null ) Create a ThreeScaleClient instance.
authorize ( $appId, $appKey = null, $serviceId = null, $usage = null ) : ThreeScaleResponse Authorize an application.
authorize_with_user_key ( $userKey, $serviceId = null, $usage = null ) : ThreeScaleResponse Authorize an application.
authrep ( $appId, $appKey = null, $usage = null, $userId = null, $object = null, $no_body = null, $serviceId = null ) : ThreeScaleResponse Authorize and report in a single shot.
authrep_with_user_key ( $userKey, $usage = null, $userId = null, $object = null, $no_body = null, $serviceId = null )
getHost ( ) : string Get hostname of 3scale backend server.
getProviderKey ( ) : string Get provider's API key.
oauth_authorize ( $appId, $serviceId = null, $usage = null ) : ThreeScaleResponse Authorize an application.
report ( $transactions, $serviceId = null ) : ThreeScaleResponse Report transaction(s).
setHttpClient ( $httpClient ) Curl library, which is just a thin wrapper around php's curl functions.

Private Methods

Method Description
buildAuthorizeResponse ( $body )
buildErrorResponse ( $body )
encodeTimestamp ( $timestamp )
encodeTransactions ( $transactions )
isHttpClientError ( $httpResponse )
isHttpStatusCodeIn ( $httpResponse, $min, $max )
isHttpSuccess ( $httpResponse )
processError ( $httpResponse )
urlencodeRecursive ( $array )

Method Details

__construct() public method

Create a ThreeScaleClient instance.
public __construct ( $providerKey, $host = self::DEFAULT_HOST, $httpClient = null )
$providerKey String Unique API key that identifies the provider.
$host String Hostname of 3scale backend server. Usually there is no reason to use anything else than the default value.
$httpClient Object Object for handling HTTP requests. Default is CURL. Don't change it unless you know what you are doing.

authorize() public method

Authorize an application.
See also: ThreeScaleAuthorizeResponse (which is derived from ThreeScaleResponse) and contains additional information about the usage status.
See also: ThreeScaleResponse
See also: ThreeScaleAuthorizeResponse
public authorize ( $appId, $appKey = null, $serviceId = null, $usage = null ) : ThreeScaleResponse
$appId application id.
$appKey secret application key.
$serviceId service id, only required in the case of multiple services
return ThreeScaleResponse object containing additional authorization information. If both provider key and application id are valid, the returned object is actually

authorize_with_user_key() public method

Authorize an application.
See also: ThreeScaleAuthorizeResponse (which is derived from ThreeScaleResponse) and contains additional information about the usage status.
See also: ThreeScaleResponse
See also: ThreeScaleAuthorizeResponse
public authorize_with_user_key ( $userKey, $serviceId = null, $usage = null ) : ThreeScaleResponse
$userKey user key.
$serviceId service id, only required in the case of multiple services
return ThreeScaleResponse object containing additional authorization information. If both provider key and application id are valid, the returned object is actually

authrep() public method

Authorize and report in a single shot.
See also: ThreeScaleAuthorizeResponse (which is derived from ThreeScaleResponse) and contains additional information about the usage status.
See also: ThreeScaleResponse
See also: ThreeScaleAuthorizeResponse
public authrep ( $appId, $appKey = null, $usage = null, $userId = null, $object = null, $no_body = null, $serviceId = null ) : ThreeScaleResponse
$appId application id.
$appKey secret application key.
return ThreeScaleResponse object containing additional authorization information. If both provider key and application id are valid, the returned object is actually

authrep_with_user_key() public method

public authrep_with_user_key ( $userKey, $usage = null, $userId = null, $object = null, $no_body = null, $serviceId = null )

getHost() public method

Get hostname of 3scale backend server.
public getHost ( ) : string
return string

getProviderKey() public method

Get provider's API key.
public getProviderKey ( ) : string
return string

oauth_authorize() public method

Authorize an application.
See also: ThreeScaleAuthorizeResponse (which is derived from ThreeScaleResponse) and contains additional information about the usage status.
See also: ThreeScaleResponse
See also: ThreeScaleAuthorizeResponse
public oauth_authorize ( $appId, $serviceId = null, $usage = null ) : ThreeScaleResponse
$appId application id or client id (they are equivalent)
$serviceId service id, only required in the case of multiple services
$usage usage
return ThreeScaleResponse object containing additional authorization information. If both provider key and application id are valid, the returned object is actually

report() public method

Report transaction(s).
public report ( $transactions, $serviceId = null ) : ThreeScaleResponse
$transactions array of transactions to report. Each transaction is an array with these elements: "app_id" - ID of the application to report the transaction for. This parameter is required. "usage" - Array of usage values. The keys are metric names and values are correspoding numeric values. Example: array('hits' => 1, 'transfer' => 1024). This parameter is required. "timestamp" - Timestamp of the transaction. This can be either an integer (the unix timestamp) or a string in the "YYYY-MM-DD HH:MM:SS" format (if the time is in the UTC), or a string in the "YYYY-MM-DD HH:MM:SS ZZZZZZ" format, where the ZZZZZZ is the time offset from the UTC. For example, "US Pacific Time" has offset -08:00, "Tokyo" has offset +09:00. This parameter is optional, and if not provided, equals to the current time.
return ThreeScaleResponse The response object's isSuccess() method returns true if the report was successful, or false if there was an error. See @see ThreeScaleResponse class for more information.

setHttpClient() public method

Curl library, which is just a thin wrapper around php's curl functions.
public setHttpClient ( $httpClient )