PHP Класс ThreeScaleClient

Objects of this class are stateless and can be shared through multiple transactions and by multiple clients.
Показать файл Открыть проект Примеры использования класса

Открытые методы

Метод Описание
__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.

Приватные методы

Метод Описание
buildAuthorizeResponse ( $body )
buildErrorResponse ( $body )
encodeTimestamp ( $timestamp )
encodeTransactions ( $transactions )
isHttpClientError ( $httpResponse )
isHttpStatusCodeIn ( $httpResponse, $min, $max )
isHttpSuccess ( $httpResponse )
processError ( $httpResponse )
urlencodeRecursive ( $array )

Описание методов

__construct() публичный Метод

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() публичный Метод

Authorize an application.
См. также: ThreeScaleAuthorizeResponse (which is derived from ThreeScaleResponse) and contains additional information about the usage status.
См. также: ThreeScaleResponse
См. также: 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
Результат ThreeScaleResponse object containing additional authorization information. If both provider key and application id are valid, the returned object is actually

authorize_with_user_key() публичный Метод

Authorize an application.
См. также: ThreeScaleAuthorizeResponse (which is derived from ThreeScaleResponse) and contains additional information about the usage status.
См. также: ThreeScaleResponse
См. также: 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
Результат ThreeScaleResponse object containing additional authorization information. If both provider key and application id are valid, the returned object is actually

authrep() публичный Метод

Authorize and report in a single shot.
См. также: ThreeScaleAuthorizeResponse (which is derived from ThreeScaleResponse) and contains additional information about the usage status.
См. также: ThreeScaleResponse
См. также: 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.
Результат 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 authrep_with_user_key ( $userKey, $usage = null, $userId = null, $object = null, $no_body = null, $serviceId = null )

getHost() публичный Метод

Get hostname of 3scale backend server.
public getHost ( ) : string
Результат string

getProviderKey() публичный Метод

Get provider's API key.
public getProviderKey ( ) : string
Результат string

oauth_authorize() публичный Метод

Authorize an application.
См. также: ThreeScaleAuthorizeResponse (which is derived from ThreeScaleResponse) and contains additional information about the usage status.
См. также: ThreeScaleResponse
См. также: 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
Результат ThreeScaleResponse object containing additional authorization information. If both provider key and application id are valid, the returned object is actually

report() публичный Метод

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.
Результат 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() публичный Метод

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