kinlane
11/17/2013 - 5:31 AM

Deploy - JSON to Secure API - Index

Deploy - JSON to Secure API - Index

<?php
require 'config.php';
require 'Slim/Slim.php';
require('lib/ThreeScaleClient.php');

$three_scale_provider_key = '[set your 3scale key, found under settings]';

\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()) {

	// Default Page
	$route = '/';
	$app->get($route, function () {
	    
	});	
	
	// Local JSON to API
	include "methods/json-to-api.php";
	
	$app->run();	

} else {
	
	$ErrorMessage = $response->getErrorMessage();
	
	//echo "Error: " . $response->getErrorMessage();
	
	// Default Page
	$route = '/';
	$app->get($route, function () {
	    
		$app->response()->status(403);	
		
	});		
	
	// productsfromjson
	$route = '/productsfromjson/';
	$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();
	
}

?>