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()); }
function testDefaultHost() { $client = new ThreeScaleClient('1234abcd'); $this->assertEqual('su1.3scale.net', $client->getHost()); }
$app = new \Slim\Slim(); // Incoming Keys $request = $app->request(); $Params = $request->params(); //var_dump($_GET); if (isset($Params['appid'])) { $appid = $Params['appid']; } else { $appid = ""; } if (isset($Params['appkey'])) { $appkey = $Params['appkey']; } else { $appkey = ""; } $client = new ThreeScaleClient($three_scale_provider_key); //echo "appid: " . $appid . "<br />"; //echo "appkey: " . $appkey . "<br />"; if ($appid != '' && $appkey != '') { // Auth the application $response = $client->authorize($appid, $appkey); $Plan = $response->getPlan(); $Plan = str_replace(" (custom)", "", $Plan); //echo $Plan . "<br />"; $usageReports = $response->getUsageReports(); $usageReport = $usageReports[0]; $Exceeded = $usageReport->isExceeded(); if ($response->isSuccess()) { $usageReports = $response->getUsageReports(); //echo "Success:"; //echo " Plan: " . $response->getPlan();
<?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":
<?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))));