Created
August 24, 2009 20:30
-
-
Save ddollar/174156 to your computer and use it in GitHub Desktop.
Display the solo teams for Rails Rumble 2009
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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