PHP code example of 3scale / 3scale_ws_api_for_php
1. Go to this page and download the library: Download 3scale/3scale_ws_api_for_php library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
3scale / 3scale_ws_api_for_php example snippets
$client = new ThreeScaleClient();
$client = new ThreeScaleClient("your provider key");
$response = $client->authorize("the app id", "the app key", "service id"));
if ($response->isSuccess()) {
// All fine, proceeed.
} else {
// Something's wrong with this app.
}
//Returns the name of the plan the application is signed up to.
$response->getPlan()
// 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
$response->getErrorCode() // "usage_limits_exceeded"
$response->getErrorMessage() // "Usage limits are exceeded"