class TBA

Public Class Methods

new(key) click to toggle source
# File lib/tbarb.rb, line 10
def initialize(key)
    @auth_key = key
end

Public Instance Methods

district_events(district, simple=false, keys=false) click to toggle source
# File lib/tbarb.rb, line 190
def district_events(district, simple=false, keys=false)
    if keys
        get("district/#{district}/events/keys")
    else
        get("district/#{district}/events#{simple ? "/simple" : ""}")
    end
end
district_rankings(district) click to toggle source
# File lib/tbarb.rb, line 198
def district_rankings(district)
    get("district/#{district}/rankings")
end
district_teams(district, simple=false, keys=false) click to toggle source
# File lib/tbarb.rb, line 202
def district_teams(district, simple=false, keys=false)
    if keys
        get("district/#{district}/teams/keys")
    else
        get("district/#{district}/teams")
    end
end
districts(year) click to toggle source
# File lib/tbarb.rb, line 186
def districts(year)
    get("districts/#{year}")
end
event(event, simple=false) click to toggle source
# File lib/tbarb.rb, line 130
def event(event, simple=false)
    get("event/#{event}#{simple ? "/simple" : ""}")
end
event_alliances(event) click to toggle source
# File lib/tbarb.rb, line 134
def event_alliances(event)
    get("event/#{event}/alliances")
end
event_awards(event) click to toggle source
# File lib/tbarb.rb, line 166
def event_awards(event)
    get("event/#{event}/awards")
end
event_district_points(event) click to toggle source
# File lib/tbarb.rb, line 138
def event_district_points(event)
    get("event/#{event}/district_points")
end
event_insights(event) click to toggle source
# File lib/tbarb.rb, line 142
def event_insights(event)
    get("event/#{event}/insights")
end
event_matches(event, simple=false, keys=false) click to toggle source
# File lib/tbarb.rb, line 170
def event_matches(event, simple=false, keys=false)
    if keys
        get("event/#{event}/matches/keys")
    else
        get("event/#{event}/matches#{simple ? "/simple" : ""}")
    end
end
event_oprs(event) click to toggle source
# File lib/tbarb.rb, line 146
def event_oprs(event)
    get("event/#{event}/oprs")
end
event_predictions(event) click to toggle source
# File lib/tbarb.rb, line 150
def event_predictions(event)
    get("event/#{event}/predictions")
end
event_rankings(event) click to toggle source
# File lib/tbarb.rb, line 154
def event_rankings(event)
    get("event/#{event}/rankings")
end
event_teams(event, simple=false, keys=false) click to toggle source
# File lib/tbarb.rb, line 158
def event_teams(event, simple=false, keys=false)
    if keys
        get("event/#{event}/teams/keys")
    else
        get("event/#{event}/teams#{simple ? "/simple" : ""}")
    end
end
events(year, simple=false, keys=false) click to toggle source
# File lib/tbarb.rb, line 122
def events(year, simple=false, keys=false)
    if keys
        get("events/#{year}/keys")
    else
        get("events/#{year}#{simple ? "/simple" : ""}")
    end
end
get(path) click to toggle source
# File lib/tbarb.rb, line 14
def get(path)
    uri = URI(@@API_ROOT + path)

    Net::HTTP.start(uri.host, uri.port,
        :use_ssl => uri.scheme == "https") do |http|
        req = Net::HTTP::Get.new(uri)
        req.add_field("X-TBA-Auth-Key", @auth_key)

        return JSON.parse(http.request(req).body)
    end
end
match(key=nil, year=nil, event=nil, type="qm", number=nil, round=nil, simple=false) click to toggle source
# File lib/tbarb.rb, line 178
def match(key=nil, year=nil, event=nil, type="qm", number=nil, round=nil, simple=false)
    if key
        get("match/#{key}#{simple ? "/simple" : ""}")
    else
        get("match/#{event[0].isDigit() ? "" : year}#{event}_#{type}#{number}#{type == "qm" ? "" : "m#{round}"}#{simple ? "/simple" : ""}")
    end
end
status() click to toggle source
# File lib/tbarb.rb, line 30
def status
    get("status")
end
team(team, simple=false) click to toggle source
# File lib/tbarb.rb, line 50
def team(team, simple=false)
    get("team/#{team_key(team)}#{simple ? "/simple" : ""}")
end
team_awards(team, year=nil, event=nil) click to toggle source
# File lib/tbarb.rb, line 70
def team_awards(team, year=nil, event=nil)
    if event
        get("team/#{team_key(team)}/event/#{event}/awards")
    else
        if year
            get("team/#{team_key(team)}/awards/#{year}")
        else
            get("team/#{team_key(team)}/awards")
        end
    end
end
team_districts(team) click to toggle source
# File lib/tbarb.rb, line 110
def team_districts(team)
    get("team/#{team_key(team)}/districts")
end
team_events(team, year=nil, simple=false, keys=false) click to toggle source
# File lib/tbarb.rb, line 54
def team_events(team, year=nil, simple=false, keys=false)
    if year
        if keys
            get("team/#{team_key(team)}/events/#{year}/keys")
        else
            get("team/#{team_key(team)}/events/#{year}#{simple ? "/simple" : ""}")
        end
    else
        if keys
            get("team/#{team_key(team)}/events/keys")
        else
            get("team/#{team_key(team)}/events#{simple ? "/simple" : ""}")
        end
    end
end
team_key(identifier) click to toggle source
# File lib/tbarb.rb, line 26
def team_key(identifier)
    return identifier.is_a?(Integer) ? "frc#{identifier}" : identifier
end
team_matches(team, event=nil, year=nil, simple=false, keys=false) click to toggle source
# File lib/tbarb.rb, line 82
def team_matches(team, event=nil, year=nil, simple=false, keys=false)
    if event
        if keys
            get("team/#{team_key(team)}/event/#{event}/matches/keys")
        else
            get("team/#{team_key(team)}/event/#{event}/matches#{simple ? "/simple" : ""}")
        end
    elsif year
        if keys
            get("team/#{team_key(team)}/matches/#{year}/keys")
        else
            get("team/#{team_key(team)}/matches/#{year}#{simple ? "/simple" : ""}")
        end
    end
end
team_media(team, year=nil, tag=nil) click to toggle source
# File lib/tbarb.rb, line 102
def team_media(team, year=nil, tag=nil)
    get("team/#{team_key(team)}/media#{tag ? ("/tag/#{tag}") : ""}#{year ? ("/#{year}") : ""}")
end
team_profiles(team) click to toggle source
# File lib/tbarb.rb, line 114
def team_profiles(team)
    get("team/#{team_key(team)}/social_media")
end
team_robots(team) click to toggle source
# File lib/tbarb.rb, line 106
def team_robots(team)
    get("team/#{team_key(team)}/robots")
end
team_status(team, event) click to toggle source
# File lib/tbarb.rb, line 118
def team_status(team, event)
    get("team/#{team_key(team)}/event/#{event}/status")
end
team_years(team) click to toggle source
# File lib/tbarb.rb, line 98
def team_years(team)
    get("team/#{team_key(team)}/years_participated")
end
teams(page, year=nil, simple=false, keys=false) click to toggle source
# File lib/tbarb.rb, line 34
def teams(page, year=nil, simple=false, keys=false)
    if year
        if keys
            get("teams/#{year}/#{page}/keys")
        else
            get("teams/#{year}/#{page}#{simple ? "/simple" : ""}")
        end
    else
        if keys
            get("teams/#{page}/keys")
        else
            get("teams/#{page}#{simple ? "/simple" : ""}")
        end
    end
end