Clean up your errors in CodeIgniter

MY_Exceptions::neat_errors() exampleIn my last post I talked about how we use and benefit from Open Source software and how we were going to start giving back to the community with our own Open Source applications and scripts. Our first Open Source script was a very small library for the Picnik API, when we released that I wanted to set a goal of releasing as much Open Source code as possible. Well, we have been busy with projects and I haven’t had time to work on much outside of projects. Today however, I created something to help me deal with PHP errors displaying in applications, that I think you might benefit from.

Cut out the frustration and stop wasting time on jumbled errors with this library.

If you’ve ever had the pleasure of seeing 30 errors appear out of nowhere on a page when you hit refresh, you know that you can’t always read them. Some are covered by other page elements, some of them run into each other, and some do both. It always leads to either placing die/exit’s in your code to try and debug, viewing the page source so you can read them, or using CodeIgniter’s built-in error logging. Read the rest of this entry »

Tags: , , , , ,
Posted in API, CodeIgniter, Development, Internet Marketing, PHP, Speaking | 3 Comments »

Proud to be Open Source

handsIt shouldn’t be a surprise that we love open source applications and languages here at Inovat, our web servers run Linux, we build our sites in PHP and Apache, and we use the CodeIgniter framework (we built our own CMS on it). Today we released our first open source file to the world, a small Picnik.com API library for CodeIgniter (though it should work in any project using PHP). You can find a link to the library below, I made sure the file was well documented and contains a good usage example.

We are proud to be developing on Open Source technologies, and our clients enjoy the benefits and cost-savings.

While I am fairly certain we won’t be open sourcing our CMS any time soon, I do hope that we can open source more libraries and scripts as we complete more projects. Questions, comments, or bugs with the Picnik script can be left here as well as ideas for libraries you’d like to see. I can’t guarantee I’ll write them, but I have no problem trying to tackle a few of them.

All Current and future open source projects can be found here. The Picnik.com library can be found in the Libraries/Picnik folder. If you use the Picnik library, drop us a link, we’d love to see what you’re doing with it.

Tags: , , , , , , , , ,
Posted in API, CodeIgniter, Development, PHP, XML | No Comments »

When Writing An XML API

It seems like every great web app has an API of some sort. Sometimes they are a complete API that allows you to use the applications entire functionality from logging in, to creating new “content”, to sending messages. Others only allow for some access for users, which I can understand. They’re usually just getting started and are not sure of how many people are going to be interested in using an API, and they don’t want to accidentally kill the application because someone’s script is stuck in a loop that repeatedly hits their server.

I personally love API’s. It’s fun building little AIR apps that talk with someone else’s hard work. If you have a web app (that is not powered by someone else’s API) and don’t plan to offer your users an API, you’re going to wish you did when your competition starts getting more attention because of what the community has built from its API. Most if not all web apps that offer API’s offer an XML version. Your script kindly asks their system for information and you get a nice XML response, which is great, every programming language supports XML (or should).

There is a problem though. Even though use of the colon and hyphen in XML tags is permitted according to the XML Recommendation at the W3C, they can be pure hell for a developer. Case in point, the other night I was playing with the Basecamp API in Flex. Basecamp’s API returns XML as expected, however you get tags like and . Great, they are valid XML names, however Flex doesn’t like it when you try:


var XMLDATA:XML = new XML(loader.data);
for each (var t:* in XMLDATA.todo-lists)
{
// Do something with the XML here.
}

It throws a fit about the hyphen because it considers it a minus sign, so my code was reading as XMLDATA.todo minus lists which obviously does nothing. I spent a great deal of time searching Google and even posted to Twitter a few times looking for help. Turns out in order to get this to work you have to do:


var XMLDATA:XML = new XML(loader.data);
for each (var t:* in XMLDATA.elements(‘todo-lists'))
{
// Do something with the XML here.
}

Does that make sense right away? Maybe to Flex developers, but to someone like myself who is only playing around with Flex and just learning, not so much. I’m not sure how Flex handles a colon in a name my guess is that it probably bombs like the hyphen does in the first example, but will work fine in the second.

There are two other things I want to touch on about building an XML API. The first is don’t make your API overly secure. Sure secure it enough that you require a username/password combo be sent via HTTP Headers, but don’t require a user to pass along a MD5 checksum of the request in order to get a response (I know someone who did this and the app really doesn’t require it). The second thing is name your tags so they are human readable, a tag with a persons user id should be called something like “user_id” or “userId” not “r”, “s”, “u”, “i”, or “p”. If you absolutely want to do that, then be kind and provide a legend for your API users to reference.

Posted in API, Development, XML | No Comments »