CakePHP 1.2 and JSON
While working on BartenderDB.com I decided to try to make the ‘data entry’ as ‘fluid’ as possible, meaning … lots and lots and LOTS of AJAX. Using jQuery of course.
While looking for some nice Cake 1.2 JSON information, I ran across an interesting post on Pagebakers called Using JSON in CakePHP 1.2. I gave it a quick read (actually, I skimmed it for code snippets and just rolled my own from the ‘general idea’) and it helped out tremendously. I was up and running with JSON in under 5 minutes. Great resource, and kudo’s to the poster.
After setting up my JSON Views, I realized that Cake was still in ‘debug’ mode — so I modified my views/layouts/json/default.ctp and simply added a Configure::write(’debug’,0); to it … and viola, problem solved, all my JSON requests were free of Cake’s added dev/staging information.
Eve Online API and PHP
A buddy of mine just recently started playing Eve Online and asked me if I could help him out by creating a small application that could help him keep track of his corporations transactions and members. He directed me to the Eve Online API Documentation and explained what he wanted to do.
I took one quick look at it, saw that they had a Python sample -- reviewed it, even tried it myself in a python shell real quick. Due to the python sample code, I almost said "Oh hey, a perfect use for Google App Engine. But then decided not to go that route, as I was hoping to host the application myself and have a bit more control over the data and the amount of data I could work with at a time. I toyed with the idea of writing it in either .NET or PHP and went with PHP. I haven't written anything in PHP for a few weeks, and I'm all over the .NET code at my day job ... so, PHP was a 'lets make things more complicated then they have to be' decision.
As such, to develop this application, I am creating what I call the 'EveAPI Class' for PHP -- which is basically just a class that has all the necessary functions and properties to retrieve any and all information accessible through the Eve Online API.
A quick example of usage is this:
-
$eve = EveAPI::Create($userID, $apiKey, $characterId);
-
$object = $eve->getCorpWalletData();
Yep, it really is that simple -- the 'toHtmlTable' is a helper function that belongs to the 'EveResult' class. The 'EveResult' class simply contains the following:
-
class EveResult {
-
var $name; // the name of the result set
-
var $count; // the number of rows in $rows
-
var $time; // the currentTime node
-
var $cachedUntil; // the cachedUntil node
-
var $api_version; // the api version
-
var $raw_response; // the actual XML response from the server
-
-
var $timeOffset; // the time offset between currentTime and time()
-
var $localExpiration; // timeOffset added to cachedUntil
-
-
-
function toHtmlTable() { /* code snipped */ }
-
}
All the functions of the EveAPI class implement a session based server-side caching, and retrieve 'cachedUntil' results from this until the 'cachedUntil' time has passed.
I haven't written much code yet to actually do what my buddy asked for, but so far, I've got a fully functional 'EveAPI Class' in PHP5 (Not sure if it's PHP4 compatible?).
I intend to release the 'EveAPI Class' to the general public once it's been tested a bit more and I've added a couple more things to it -- right now, all the functions are targetted toward corporation data only ('/corp/' page requests). I intend to add the '/char/' page requests, shortly.


