Skip to content

Instantly share code, notes, and snippets.

@ddollar
Created August 24, 2009 20:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save ddollar/174156 to your computer and use it in GitHub Desktop.
Save ddollar/174156 to your computer and use it in GitHub Desktop.
Display the solo teams for Rails Rumble 2009
require 'httparty'
API_KEY = 'YOUR_API_KEY'
class Hash
def method_missing(key)
self[key.to_s] || super
end
end
class Team < Hash
include HTTParty
format :json
base_uri 'http://r09.railsrumble.com'
default_params :api_key => API_KEY
def self.all
page = 1
teams = []
until (raw_teams = by_page(page)).length.zero?
teams.concat(raw_teams.map { |team| new(team.slug) })
page += 1
end
teams
end
def self.by_page(page)
get('/teams.json', :query => { :page => page }).map { |team| team['team'] }
end
def self.singles
all.select { |team| team.members.length == 1 }
end
def initialize(slug)
self.merge!(self.class.get("/teams/#{slug}.json")['team'])
end
def team_page_url
"http://r09.railsrumble.com/teams/#{slug}"
end
end
Team.singles.sort_by { |team| team.name.upcase }.each do |team|
puts("%30s - %s" % [team.name[0..29], team.entry.direct_url])
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment