Skip to content

Instantly share code, notes, and snippets.

@jerzyn
Last active August 29, 2015 13:57
Show Gist options
  • Select an option

  • Save jerzyn/9689187 to your computer and use it in GitHub Desktop.

Select an option

Save jerzyn/9689187 to your computer and use it in GitHub Desktop.
PHP plugin setup
$response = $client->authorize("the app id", "the app key");
$client = new ThreeScaleClient("your provider key");
$response->getErrorCode(); // "provider_key_invalid"
$response->getErrorMessage(); // "provider key \"foo\" is invalid"
$response->getErrorCode(); // "usage_limits_exceeded"
$response->getErrorMessage(); // "Usage limits are exceeded"
// Returns the name of the plan the application is signed up to.
$response->getPlan();
if ($response->isSuccess()) {
// All fine, proceeed.
} else {
// Something's wrong with this app.
}
require_once('lib/ThreeScaleClient.php')
if ($response->isSuccess()) {
// All OK.
} else {
// There was an error.
}
$response = $client->report(array( array('app_id' => "app's id", 'usage' => array('hits' => 1), 'timestamp' => mktime(12, 36, 0, 4, 28, 2010))));
$response = $client->report(array( array('app_id' => "first app's id", 'usage' => array('hits' => 1)), array('app_id' => "second app's id", 'usage' => array('hits' => 1))));
require_once('lib/ThreeScaleClient.php')
// The usageReports array contains one element per each usage limit defined on the plan.
$usageReports = $response->getUsageReports();
$usageReport = $usageReports[0]; // The metric
$usageReport->getMetric(); // "hits"
// The period the limit applies to
$usageReport->getPeriod(); // "day"
$usageReport->getPeriodStart(); // 1272405600 (Unix timestamp for April 28, 2010, 00:00:00)
$usageReport->getPeriodEnd(); // 1272492000 (Unix timestamp for April 29, 2010, 00:00:00)
// The current value the application already consumed in the period
$usageReport->getCurrentValue();// 8032
// The maximal value allowed by the limit in the period
$usageReport->getMaxValue(); // 10000
// If the limit is exceeded, this will be true, otherwise false:
$usageReport->isExceeded(); // false
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment