Popcorn.js jsonp request for milestones

Today for the CDOT dashboard project, I finished up a php server to serve jsonp data for popcorn.sj’s milestone data inside lighthouse.

You can access it via JavaScript like so:

$.ajax({
    url: "http://scotland.proximity.on.ca/sdowne/sqlite/jsonp.php?service=lighthouse&callback=foo",
    dataType: "JSONP",
    type: "GET",
    success: function( data ) {
        console.log( data );
    }
});

With the data argument in the success function being your shiny new json data.

It is being tested and reviewed by Dave currently, who is the one that needed the jsonp data in the first place.

The obvious reason for this existing is to allow thing like json to be requested via server side scripting (JavaScript), and to my knowledge this does not exist yet for lighthouse. Another reason for this existing, is it reduces the number of calls to lighthouse. I was initially going to setup an internal timer, which would update the data served every half hour. I ended up thinking up a much much better solution. Instead, I would hold timestamps on the last time the data was updated, then, when someone requests that data, check if the timestamp is more than 30 minutes ago, if so, update via lighthouse json request, and set timestamp as the current time. This saves unneeded calls, so I ONLY update the server side data if a request is made, instead of a blind cron job. Also is much easier, and much less code.

The internals ended up storing the data on a very very simple sqlite layout. I am actually enjoying using sqlite via php very much. I just used php’s exec function to directly call and manipulate my sqlite database. No passwords, no connections, no remote.

For now I only serve popcorn’s milestone info, because there was no other way to get it, and I figured it would be a useful hello world test, but in the future we will add more to it, as needed.

I’ll be adding the source to github later today, but there is some setup that is required to get it working, that is why I setup a link on scotland.proximity.on.ca. Also, I figure it can be used by someone interested in this data for other projects.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: