kinlane
11/30/2013 - 5:08 AM

FAFSA API - Secured Index w/ 3Scale

FAFSA API - Secured Index w/ 3Scale

<?php
require 'config.php';
require 'Slim/Slim.php';

require('lib/ThreeScaleClient.php');

\Slim\Slim::registerAutoloader();
$app = new \Slim\Slim();

// Incoming Keys
if(isset($_REQUEST['appid'])){ $appid = $_REQUEST['appid']; } elseif(isset($_POST['appid'])){ $appid = $_POST['appid']; } else { $appid = '';}	
if(isset($_REQUEST['appkey'])){ $appkey = $_REQUEST['appkey']; } elseif(isset($_POST['appkey'])){ $appkey = $_POST['appkey']; } else { $appkey = '';}

$client = new ThreeScaleClient($three_scale_provider_key);

// Auth the application
$response = $client->authorize($appid, $appkey);

//var_dump($response);
// Check the response type
if ($response->isSuccess()) {

	$route = '/';
	$app->get($route, function () {	
	});	
	
	include "methods/applications.php";
	
	$app->run();
	
} else {
	
	$ErrorMessage = $response->getErrorMessage();
	
	//echo "Error: " . $response->getErrorMessage();
	
	// Default Page
	$route = '/';
	$app->get($route, function () {
	    
		$app->response()->status(403);	
		
	});		
	
	// productsfromjson
	$route = '/applications/';
	$app->get($route, function ()  use ($app,$ErrorMessage){
	    
		$E = array();											
		$E['Message'] = $ErrorMessage;	
	
		$app->response()->status(403);	
		$app->response()->header("Content-Type", "application/json");
		echo format_json(json_encode($E));				
		
	});	
	
	$app->run();
	
}	
?>