Class: TBA

Inherits:
Object
  • Object
show all
Defined in:
lib/tbarb.rb

Constant Summary collapse

@@API_ROOT =
"https://www.thebluealliance.com/api/v3/"

Instance Method Summary collapse

Constructor Details

#initialize(key) ⇒ TBA

Returns a new instance of TBA.



10
11
12
# File 'lib/tbarb.rb', line 10

def initialize(key)
    @auth_key = key
end

Instance Method Details

#district_events(district, simple = false, keys = false) ⇒ Object



190
191
192
193
194
195
196
# 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) ⇒ Object



198
199
200
# File 'lib/tbarb.rb', line 198

def district_rankings(district)
    get("district/#{district}/rankings")
end

#district_teams(district, simple = false, keys = false) ⇒ Object



202
203
204
205
206
207
208
# 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) ⇒ Object



186
187
188
# File 'lib/tbarb.rb', line 186

def districts(year)
    get("districts/#{year}")
end

#event(event, simple = false) ⇒ Object



130
131
132
# File 'lib/tbarb.rb', line 130

def event(event, simple=false)
    get("event/#{event}#{simple ? "/simple" : ""}")
end

#event_alliances(event) ⇒ Object



134
135
136
# File 'lib/tbarb.rb', line 134

def event_alliances(event)
    get("event/#{event}/alliances")
end

#event_awards(event) ⇒ Object



166
167
168
# File 'lib/tbarb.rb', line 166

def event_awards(event)
    get("event/#{event}/awards")
end

#event_district_points(event) ⇒ Object



138
139
140
# File 'lib/tbarb.rb', line 138

def event_district_points(event)
    get("event/#{event}/district_points")
end

#event_insights(event) ⇒ Object



142
143
144
# File 'lib/tbarb.rb', line 142

def event_insights(event)
    get("event/#{event}/insights")
end

#event_matches(event, simple = false, keys = false) ⇒ Object



170
171
172
173
174
175
176
# 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) ⇒ Object



146
147
148
# File 'lib/tbarb.rb', line 146

def event_oprs(event)
    get("event/#{event}/oprs")
end

#event_predictions(event) ⇒ Object



150
151
152
# File 'lib/tbarb.rb', line 150

def event_predictions(event)
    get("event/#{event}/predictions")
end

#event_rankings(event) ⇒ Object



154
155
156
# File 'lib/tbarb.rb', line 154

def event_rankings(event)
    get("event/#{event}/rankings")
end

#event_teams(event, simple = false, keys = false) ⇒ Object



158
159
160
161
162
163
164
# 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) ⇒ Object



122
123
124
125
126
127
128
# 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) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# 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) ⇒ Object



178
179
180
181
182
183
184
# 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

#statusObject



30
31
32
# File 'lib/tbarb.rb', line 30

def status
    get("status")
end

#team(team, simple = false) ⇒ Object



50
51
52
# 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) ⇒ Object



70
71
72
73
74
75
76
77
78
79
80
# 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) ⇒ Object



110
111
112
# 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) ⇒ Object



54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# 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) ⇒ Object



26
27
28
# 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) ⇒ Object



82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# 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) ⇒ Object



102
103
104
# 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) ⇒ Object



114
115
116
# File 'lib/tbarb.rb', line 114

def team_profiles(team)
    get("team/#{team_key(team)}/social_media")
end

#team_robots(team) ⇒ Object



106
107
108
# File 'lib/tbarb.rb', line 106

def team_robots(team)
    get("team/#{team_key(team)}/robots")
end

#team_status(team, event) ⇒ Object



118
119
120
# File 'lib/tbarb.rb', line 118

def team_status(team, event)
    get("team/#{team_key(team)}/event/#{event}/status")
end

#team_years(team) ⇒ Object



98
99
100
# 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) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
# 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