-
-
Save amiel/174857 to your computer and use it in GitHub Desktop.
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
api_key.txt |
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 = File.read('api_key.txt').chomp | |
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