Tribesports Tech Blog

25 press-ups for breaking the build...

Pub/Sub System Events for Post-action Tasks

| Comments


Rails controllers are often a dumping ground for unrelated tasks. We cleaned ours up using a pub/sub system of announced events and task-specific listeners. This made our app easier to modify, easier to test, and easier to read. Probably.

Separating API Logic With Decorators

| Comments

In our last post we demonstrated how to use Rails 3’s response and rendering system to provide a cleanly-versioned API. By defining a custom MIME type and a renderer for that type, we were able to version our API, and handle responses without any changes to our controllers.

However, we were left with unsightly #to_api_v1 methods on all of our business models. We’d like to separate presentation logic from our business logic, and to do that we’re going to use decorators. We’re making use of Jeff Casimir’s draper gem, which provides some nice convenience methods for decorating Rails models.

Versioning the Tribesports API

| Comments

As Andrew is hard at work on the upcoming Tribesports iPhone app, we’ve been paying a bit of attention to our API. Where previously we had responded to JSON requests in a rather ad-hoc fashion according to our application’s internal needs, a full-blown API requires a more systematic approach.

Our goals are as follows:

  1. Allow clean API versioning
  2. Separate API presentation logic from business models
  3. Minimise additional controller complexity