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.
 function testFailedReport()
 {
     $transactions = array();
     foreach ($this->appIds as $appId) {
         array_push($transactions, array('app_id' => $appId, 'usage' => array('hits' => 1)));
     }
     $client = new ThreeScaleClient('boo');
     $response = $client->report($transactions);
     $this->assertFalse($response->isSuccess());
     $this->assertEqual('provider_key_invalid', $response->getErrorCode());
     $this->assertEqual('provider key "boo" is invalid', $response->getErrorMessage());
 }
示例#2
0
    $Exceeded = $usageReport->isExceeded();
    if ($response->isSuccess()) {
        $usageReports = $response->getUsageReports();
        //echo "Success:";
        //echo "  Plan: " .          $response->getPlan();
        //echo "  Usage reports: " . var_export($usageReports, true);
        if ($Plan == "Internal" || $Plan == "Platform") {
            include "methods/platform.php";
            include "methods/utility.php";
        } elseif ($Plan == "Personal") {
            include "methods/personal.php";
        } elseif ($Plan == "Partner") {
            include "methods/partner.php";
        } elseif ($Plan == "Trusted") {
            include "methods/trusted.php";
        } elseif ($Plan == "Retail") {
            include "methods/retail.php";
        } else {
            include "methods/public.php";
        }
        $app->run();
        // Report some usages
        $response = $client->report(array(array('app_id' => $appid, 'usage' => array('screen-capture' => 1))));
    } else {
        include "methods/public.php";
        $app->run();
    }
} else {
    include "methods/public.php";
    $app->run();
}
<?php

require dirname(__FILE__) . '/../lib/ThreeScaleClient.php';
// Put your provider key here:
$provider_key = "aaa";
// Put some app_ids here (you can test it with the one from test contract):
$app_id_one = "bbb";
$app_id_two = "ccc";
// Put a app key corresponding to the first app_id here (you can leave it empty, if
// the app has no keys defined.)
$app_key_one = "";
$client = new ThreeScaleClient($provider_key);
// Auth the application
$response = $client->authorize($app_id_one, $app_key_one);
// Check the response type
if ($response->isSuccess()) {
    // All fine, proceeed & pull the usage reports
    $usageReports = $response->getUsageReports();
    echo "Success:";
    echo "  Plan: " . $response->getPlan();
    echo "  Usage reports: " . var_export($usageReports, true);
} else {
    // Something's wrong with this app.
    echo "Error: " . $response->getErrorMessage();
}
// Report some usages
$response = $client->report(array(array('app_id' => $app_id_one, 'usage' => array('hits' => 1)), array('app_id' => $app_id_two, 'usage' => array('hits' => 1))));