This snippet is something I put together to play around with the FestivalsLab API inside a Rails app I was building. I built it with Rails 3 on Ruby 1.9.2 but there's no reason it shouldn't work on older versions of either of those.
This could potentially be used as a bare Ruby library without Rails, but I am using a couple of useful features - Rack's query string parsing and some MIME type handling - that would have to be rewritten to do that. I'm using these features because I don't think that any URI string manipulation should happen outside of a URI library, your philosophy may be different ;)
This code should be considered a work in progress, there are no guarantees that it will work for you, or that it won't wipe your hard drive. But you can see the code, it's all pretty simple.
The best way to integrate this into your Rails app at the moment is to copy the enclosed files into your /lib
folder, then create an initializer in /config/initializers
which loads the FestivalsLab code and contains your API keys:
require 'festivals_lab'
FestivalsLab.setup do |config|
config.access_key = ...
config.secret_key = ...
end
Once loaded, FestivalsLab.events()
and FestivalsLab.event()
can be called from your app as documented in the code, to retrieve nested Hash
es of the API data based on the JSON data feed. The library doesn't do any caching or processing of the data, that's all up to you :)