ThreeScaleClient::authorize_with_user_key PHP Метод

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
    public function authorize_with_user_key($userKey, $serviceId = null, $usage = null)
    {
        $url = "http://" . $this->getHost() . "/transactions/authorize.xml";
        $params = array('provider_key' => $this->getProviderKey(), 'user_key' => $userKey);
        if ($serviceId) {
            $params['service_id'] = $serviceId;
        }
        if ($usage) {
            $params['usage'] = $usage;
        }
        $httpResponse = $this->httpClient->get($url, $params);
        if (self::isHttpSuccess($httpResponse)) {
            return $this->buildAuthorizeResponse($httpResponse->body);
        } else {
            return $this->processError($httpResponse);
        }
    }

Usage Example

<?php

require_once 'lib/ThreeScaleClient.php';
$client = new ThreeScaleClient("YOUR_PROVIDER_KEY");
$response = $client->authorize_with_user_key($_GET["user_key"]);
function speech_app_list()
{
    //normally this info would be pulled from a database.
    //build JSON array
    //report against metric
    global $client;
    $client->report(array(array('user_key' => $_GET["user_key"], 'usage' => array('speech' => 1))));
    $app_list = array(array("id" => 1, "name" => "Web Demo"), array("id" => 2, "name" => "Audio Countdown"), array("id" => 3, "name" => "The Tab Key"), array("id" => 4, "name" => "Music Sleep Timer"));
    return $app_list;
}
function enroll_app_list()
{
    //normally this info would be pulled from a database.
    //build JSON array
    //report against metric
    global $client;
    $client->report(array(array('user_key' => $_GET["user_key"], 'usage' => array('enroll' => 1))));
    $app_list = array(array("id" => 1, "name" => "Enroll abc"), array("id" => 2, "name" => "Enroll efg"), array("id" => 3, "name" => "Enroll mnp"), array("id" => 4, "name" => "Enroll xyz"));
    return $app_list;
}
if ($response->isSuccess()) {
    $possible_url = array("speech_list", "enroll_list");
    $value = "An error has occurred";
    if (isset($_GET["action"]) && in_array($_GET["action"], $possible_url)) {
        switch ($_GET["action"]) {
            case "speech_list":