Skip to content

Implementing a Provider (ActiveResource)

kiafaldorius edited this page Sep 14, 2010 · 3 revisions

This page describes basic instructions for implementing a provider using ActiveResource as interface to your API.

Since ActiveResource is big in the Ruby on Rails community, most sites that cater to RoR will go out of their way to support ActiveResource. If the XML version doesn’t work, a handful of APIs also provide a JSON alternative—which ActiveResource will be able to parse and utilize as well. Therefore, with exception to a few odd APIs, most will be able to work with ActiveResource (possibly with a couple of functionality inaccessible such as file uploads, but TicketMaster doesn’t deal with uploads anyway, so it’s not a problem).

Generate the Skeleton

TicketMaster has built-in functionality to generate a skeleton with the basic files necessary to implement a provider. It integrates with Jeweler as well, so if you’re using it, you’re in luck.

tm generate providername --jeweler --rspec --gemcutter --summary "The providername provider for ticketmaster"

This command will create a new gem through jeweler with the name “ticketmaster-providername” and all the corresponding jeweler files, and then add in the provider skeleton files inside the lib directory.

tm generate providername

This command will only create a directory (or add to if it already exists) named “ticketmaster-providername” and then add provider skeleton files inside the lib directory. This assumes you’ll be using something else to do your gem packaging.

Defining the API

If your ActiveResource API implementation is a gem, you can just include it in your gem dependencies.

If you don’t want to package it as a gem or would rather it be a file, it is recommended that you create a new directory under the lib for your ActiveResource files and require it from inside your lib/ticketmaster-providername.rb file.

Define the Authentication and API Classes

authorize

You will need to define the API authentication function. Open your provider’s lib/provider/providername.rb file and edit the authorize method to set the authentication parameters for your API.

API classes

Near the top of lib/provider/providername.rb are two constants, TICKET_API and PROJECT_API. Uncomment and set them to the class of your ActiveResource API for the Ticket and Project.

Also inside the lib/provider directory are also three more files, project.rb ticket.rb and comment.rb. Each of those has an API constant, set it to the class of the respective ActiveResource API.

Redefine Methods

Map different methods to the TicketMaster methods. Docs on this coming soon.