tbarb 0.3.0 → 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/tbarb.rb +209 -0
  3. metadata +3 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e270a4009110a8c11c851c789534775e7df2263a
4
- data.tar.gz: c1d4f101972fc0a288f0ed19a9393ab911884a94
3
+ metadata.gz: a7178cdb8a6098e93128561209e735d014774c22
4
+ data.tar.gz: 7e794f4b13937dada0c6b563ede828d63252fef4
5
5
  SHA512:
6
- metadata.gz: d826182683698e5e40e600e3fdde46da94823596f5cbf1ee2a3b9f8eb8856a55539cff3a98021d63acabd33df2cca80ee3f76f0abd99f434ce43c755674cf22f
7
- data.tar.gz: e1bc787a00cbba5d06af42c00dfedea9b6e58427fc98d78049e103e2048a8fad9e970c51dafe71be99469d99969f4b7c3bafa0061b13985cb7b69232c14a8556
6
+ metadata.gz: 400d0f95d8e3dce6ac6f22ff70f9f55768d5e5a5f7df76317eca576c981cd86a4e52765c2040b749346f8ebfdfb4b0a3881d1eadc1e8d7886e7d3c2f481c7b41
7
+ data.tar.gz: 3de9ec146e9cc244fa67e36aaafa595f715f13ecbfd8eae973676475ad350f1fd407c82a6d7f08fc92d16ffa9b68177e8f112456bbd60b64a009dbac8145d2f4
@@ -0,0 +1,209 @@
1
+ require "net/http"
2
+ require "uri"
3
+ require "json"
4
+
5
+ class TBA
6
+
7
+ @@API_ROOT = "https://www.thebluealliance.com/api/v3/"
8
+ @auth_key = ""
9
+
10
+ def initialize(key)
11
+ @auth_key = key
12
+ end
13
+
14
+ def get(path)
15
+ uri = URI(@@API_ROOT + path)
16
+
17
+ Net::HTTP.start(uri.host, uri.port,
18
+ :use_ssl => uri.scheme == "https") do |http|
19
+ req = Net::HTTP::Get.new(uri)
20
+ req.add_field("X-TBA-Auth-Key", @auth_key)
21
+
22
+ return JSON.parse(http.request(req).body)
23
+ end
24
+ end
25
+
26
+ def team_key(identifier)
27
+ return identifier.is_a?(Integer) ? "frc#{identifier}" : identifier
28
+ end
29
+
30
+ def status
31
+ get("status")
32
+ end
33
+
34
+ def teams(page, year=nil, simple=false, keys=false)
35
+ if year
36
+ if keys
37
+ get("teams/#{year}/#{page}/keys")
38
+ else
39
+ get("teams/#{year}/#{page}#{simple ? "/simple" : ""}")
40
+ end
41
+ else
42
+ if keys
43
+ get("teams/#{page}/keys")
44
+ else
45
+ get("teams/#{page}#{simple ? "/simple" : ""}")
46
+ end
47
+ end
48
+ end
49
+
50
+ def team(team, simple=false)
51
+ get("team/#{team_key(team)}#{simple ? "/simple" : ""}")
52
+ end
53
+
54
+ def team_events(team, year=nil, simple=false, keys=false)
55
+ if year
56
+ if keys
57
+ get("team/#{team_key(team)}/events/#{year}/keys")
58
+ else
59
+ get("team/#{team_key(team)}/events/#{year}#{simple ? "/simple" : ""}")
60
+ end
61
+ else
62
+ if keys
63
+ get("team/#{team_key(team)}/events/keys")
64
+ else
65
+ get("team/#{team_key(team)}/events#{simple ? "/simple" : ""}")
66
+ end
67
+ end
68
+ end
69
+
70
+ def team_awards(team, year=nil, event=nil)
71
+ if event
72
+ get("team/#{team_key(team)}/event/#{event}/awards")
73
+ else
74
+ if year
75
+ get("team/#{team_key(team)}/awards/#{year}")
76
+ else
77
+ get("team/#{team_key(team)}/awards")
78
+ end
79
+ end
80
+ end
81
+
82
+ def team_matches(team, event=nil, year=nil, simple=false, keys=false)
83
+ if event
84
+ if keys
85
+ get("team/#{team_key(team)}/event/#{event}/matches/keys")
86
+ else
87
+ get("team/#{team_key(team)}/event/#{event}/matches#{simple ? "/simple" : ""}")
88
+ end
89
+ elsif year
90
+ if keys
91
+ get("team/#{team_key(team)}/matches/#{year}/keys")
92
+ else
93
+ get("team/#{team_key(team)}/matches/#{year}#{simple ? "/simple" : ""}")
94
+ end
95
+ end
96
+ end
97
+
98
+ def team_years(team)
99
+ get("team/#{team_key(team)}/years_participated")
100
+ end
101
+
102
+ def team_media(team, year=nil, tag=nil)
103
+ get("team/#{team_key(team)}/media#{tag ? ("/tag/#{tag}") : ""}#{year ? ("/#{year}") : ""}")
104
+ end
105
+
106
+ def team_robots(team)
107
+ get("team/#{team_key(team)}/robots")
108
+ end
109
+
110
+ def team_districts(team)
111
+ get("team/#{team_key(team)}/districts")
112
+ end
113
+
114
+ def team_profiles(team)
115
+ get("team/#{team_key(team)}/social_media")
116
+ end
117
+
118
+ def team_status(team, event)
119
+ get("team/#{team_key(team)}/event/#{event}/status")
120
+ end
121
+
122
+ def events(year, simple=false, keys=false)
123
+ if keys
124
+ get("events/#{year}/keys")
125
+ else
126
+ get("events/#{year}#{simple ? "/simple" : ""}")
127
+ end
128
+ end
129
+
130
+ def event(event, simple=false)
131
+ get("event/#{event}#{simple ? "/simple" : ""}")
132
+ end
133
+
134
+ def event_alliances(event)
135
+ get("event/#{event}/alliances")
136
+ end
137
+
138
+ def event_district_points(event)
139
+ get("event/#{event}/district_points")
140
+ end
141
+
142
+ def event_insights(event)
143
+ get("event/#{event}/insights")
144
+ end
145
+
146
+ def event_oprs(event)
147
+ get("event/#{event}/oprs")
148
+ end
149
+
150
+ def event_predictions(event)
151
+ get("event/#{event}/predictions")
152
+ end
153
+
154
+ def event_rankings(event)
155
+ get("event/#{event}/rankings")
156
+ end
157
+
158
+ def event_teams(event, simple=false, keys=false)
159
+ if keys
160
+ get("event/#{event}/teams/keys")
161
+ else
162
+ get("event/#{event}/teams#{simple ? "/simple" : ""}")
163
+ end
164
+ end
165
+
166
+ def event_awards(event)
167
+ get("event/#{event}/awards")
168
+ end
169
+
170
+ def event_matches(event, simple=false, keys=false)
171
+ if keys
172
+ get("event/#{event}/matches/keys")
173
+ else
174
+ get("event/#{event}/matches#{simple ? "/simple" : ""}")
175
+ end
176
+ end
177
+
178
+ def match(key=nil, year=nil, event=nil, type="qm", number=nil, round=nil, simple=false)
179
+ if key
180
+ get("match/#{key}#{simple ? "/simple" : ""}")
181
+ else
182
+ get("match/#{event[0].isDigit() ? "" : year}#{event}_#{type}#{number}#{type == "qm" ? "" : "m#{round}"}#{simple ? "/simple" : ""}")
183
+ end
184
+ end
185
+
186
+ def districts(year)
187
+ get("districts/#{year}")
188
+ end
189
+
190
+ def district_events(district, simple=false, keys=false)
191
+ if keys
192
+ get("district/#{district}/events/keys")
193
+ else
194
+ get("district/#{district}/events#{simple ? "/simple" : ""}")
195
+ end
196
+ end
197
+
198
+ def district_rankings(district)
199
+ get("district/#{district}/rankings")
200
+ end
201
+
202
+ def district_teams(district, simple=false, keys=false)
203
+ if keys
204
+ get("district/#{district}/teams/keys")
205
+ else
206
+ get("district/#{district}/teams")
207
+ end
208
+ end
209
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: tbarb
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Erik Boesen
@@ -16,7 +16,8 @@ email: robotics1418@gmail.com
16
16
  executables: []
17
17
  extensions: []
18
18
  extra_rdoc_files: []
19
- files: []
19
+ files:
20
+ - lib/tbarb.rb
20
21
  homepage: https://github.com/frc1418/tbarb
21
22
  licenses:
22
23
  - MIT