Last active
August 29, 2015 13:57
-
-
Save jerzyn/9689187 to your computer and use it in GitHub Desktop.
PHP plugin setup
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $client = new ThreeScaleClient("your provider key"); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $response->getErrorCode(); // "provider_key_invalid" | |
| $response->getErrorMessage(); // "provider key \"foo\" is invalid" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $response->getErrorCode(); // "usage_limits_exceeded" | |
| $response->getErrorMessage(); // "Usage limits are exceeded" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // Returns the name of the plan the application is signed up to. | |
| $response->getPlan(); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if ($response->isSuccess()) { | |
| // All fine, proceeed. | |
| } else { | |
| // Something's wrong with this app. | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require_once('lib/ThreeScaleClient.php') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| if ($response->isSuccess()) { | |
| // All OK. | |
| } else { | |
| // There was an error. | |
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $response = $client->report(array( array('app_id' => "app's id", 'usage' => array('hits' => 1), 'timestamp' => mktime(12, 36, 0, 4, 28, 2010)))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| $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)))); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| require_once('lib/ThreeScaleClient.php') |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| // 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