AllSportDB 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/allsportdb_api.rb +306 -0
- metadata +43 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: a3deb725072d02430da2a42884a64cb095921a3239f80ebb2cc7d5e7466fcd78
|
4
|
+
data.tar.gz: 914cd86300dffb63c40af9f73d7d7d76a986700f44700e92980a2121060fa4d9
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: '0497373ad3e3a6b9229466c66d99a782d761167bba9a373cf4a5cf8af65c8bce8bf4da80f10dc2ecba324782fddd7f708724ead71eae5e55aa51973532df0433'
|
7
|
+
data.tar.gz: c065e7790aa7028cf11309ff4f5011f7beee00a926104230cfc1aebec0cb8003aab24e7181bd520147459cc992ecc4006c6a824f2699f937b11f1e30f662cb42
|
@@ -0,0 +1,306 @@
|
|
1
|
+
require 'uri'
|
2
|
+
require 'net/http'
|
3
|
+
require 'json'
|
4
|
+
require 'date'
|
5
|
+
|
6
|
+
class AllSportDB
|
7
|
+
|
8
|
+
private_class_method def self.CallAPI(method, params, key)
|
9
|
+
root = 'https://api.allsportdb.com/v3/'
|
10
|
+
uri = URI(root + method)
|
11
|
+
headers = { 'Authorization'=>'Bearer ' + key }
|
12
|
+
|
13
|
+
page = 0
|
14
|
+
while true
|
15
|
+
page += 1
|
16
|
+
call_params = params
|
17
|
+
params[:page] = page
|
18
|
+
|
19
|
+
uri.query = URI.encode_www_form(call_params)
|
20
|
+
res = Net::HTTP.get_response(uri, headers)
|
21
|
+
|
22
|
+
if res.kind_of? Net::HTTPUnauthorized
|
23
|
+
raise Exception.new "API error: Unauthorized [#{res.class}]"
|
24
|
+
end
|
25
|
+
if not res.kind_of? Net::HTTPSuccess
|
26
|
+
raise Exception.new "API error: Unknown error [#{res.class}]"
|
27
|
+
end
|
28
|
+
|
29
|
+
call_items = JSON.parse(res.body, object_class: OpenStruct)
|
30
|
+
|
31
|
+
if page == 1
|
32
|
+
items = call_items
|
33
|
+
else
|
34
|
+
items = items + call_items
|
35
|
+
end
|
36
|
+
|
37
|
+
if call_items.length() != 10 && call_items.length() != 100 && call_items.length() != 1000
|
38
|
+
break
|
39
|
+
end
|
40
|
+
end
|
41
|
+
|
42
|
+
return items
|
43
|
+
end
|
44
|
+
|
45
|
+
def self.GetCalendar(
|
46
|
+
key:,
|
47
|
+
week: 0,
|
48
|
+
dateFrom: nil,
|
49
|
+
dateTo: nil,
|
50
|
+
dateToday: nil,
|
51
|
+
year: nil,
|
52
|
+
eventId: nil,
|
53
|
+
event: nil,
|
54
|
+
locationId: nil,
|
55
|
+
location: nil,
|
56
|
+
competitionId: nil,
|
57
|
+
competition: nil,
|
58
|
+
sportId: nil,
|
59
|
+
sport: nil,
|
60
|
+
countryId: nil,
|
61
|
+
country: nil,
|
62
|
+
regionId: nil,
|
63
|
+
region: nil,
|
64
|
+
continentId: nil,
|
65
|
+
continent: nil,
|
66
|
+
locationContinentId: nil,
|
67
|
+
locationContinent: nil,
|
68
|
+
liveUrlExists: nil,
|
69
|
+
filter: nil
|
70
|
+
)
|
71
|
+
params = {
|
72
|
+
:week => week,
|
73
|
+
:dateFrom => dateFrom,
|
74
|
+
:dateTo => dateTo,
|
75
|
+
:dateToday => dateToday,
|
76
|
+
:year => year,
|
77
|
+
:eventId => eventId,
|
78
|
+
:event => event,
|
79
|
+
:locationId => locationId,
|
80
|
+
:location => location,
|
81
|
+
:competitionId => competitionId,
|
82
|
+
:competition => competition,
|
83
|
+
:sportId => sportId,
|
84
|
+
:sport => sport,
|
85
|
+
:countryId => countryId,
|
86
|
+
:country => country,
|
87
|
+
:regionId => regionId,
|
88
|
+
:region => region,
|
89
|
+
:continentId => continentId,
|
90
|
+
:continent => continent,
|
91
|
+
:locationContinentId => locationContinentId,
|
92
|
+
:locationContinent => locationContinent,
|
93
|
+
:liveUrlExists => liveUrlExists,
|
94
|
+
:filter => filter
|
95
|
+
}
|
96
|
+
items = CallAPI('calendar', params, key)
|
97
|
+
return items
|
98
|
+
end
|
99
|
+
|
100
|
+
def self.GetEvent(
|
101
|
+
key:,
|
102
|
+
id: 0
|
103
|
+
)
|
104
|
+
params = {
|
105
|
+
:eventId => id,
|
106
|
+
:dateFrom => DateTime.new(2000, 1, 1),
|
107
|
+
:dateTo => DateTime.new(2200, 1, 1)
|
108
|
+
}
|
109
|
+
items = CallAPI('calendar', params, key)
|
110
|
+
if items.length() == 0
|
111
|
+
raise Exception.new "API error: item not found"
|
112
|
+
end
|
113
|
+
return items[0]
|
114
|
+
end
|
115
|
+
|
116
|
+
def self.GetSports(
|
117
|
+
key:,
|
118
|
+
season: nil
|
119
|
+
)
|
120
|
+
params = {
|
121
|
+
:season => season
|
122
|
+
}
|
123
|
+
items = CallAPI('sports', params, key)
|
124
|
+
return items
|
125
|
+
end
|
126
|
+
|
127
|
+
def self.GetSport(
|
128
|
+
key:,
|
129
|
+
id: 0,
|
130
|
+
name: nil
|
131
|
+
)
|
132
|
+
params = {
|
133
|
+
:id => id,
|
134
|
+
:name => name
|
135
|
+
}
|
136
|
+
items = CallAPI('sports', params, key)
|
137
|
+
if items.length() == 0
|
138
|
+
raise Exception.new "API error: item not found"
|
139
|
+
end
|
140
|
+
return items[0]
|
141
|
+
end
|
142
|
+
|
143
|
+
def self.GetCompetitions(
|
144
|
+
key:,
|
145
|
+
sportId: nil,
|
146
|
+
sport: nil,
|
147
|
+
continentId: nil,
|
148
|
+
continent: nil
|
149
|
+
)
|
150
|
+
params = {
|
151
|
+
:sportId => sportId,
|
152
|
+
:sport => sport,
|
153
|
+
:continentId => continentId,
|
154
|
+
:continent => continent,
|
155
|
+
}
|
156
|
+
items = CallAPI('competitions', params, key)
|
157
|
+
return items
|
158
|
+
end
|
159
|
+
|
160
|
+
def self.GetCompetition(
|
161
|
+
key:,
|
162
|
+
id: 0,
|
163
|
+
name: nil
|
164
|
+
)
|
165
|
+
params = {
|
166
|
+
:id => id,
|
167
|
+
:name => name
|
168
|
+
}
|
169
|
+
items = CallAPI('competitions', params, key)
|
170
|
+
if items.length() == 0
|
171
|
+
raise Exception.new "API error: item not found"
|
172
|
+
end
|
173
|
+
return items[0]
|
174
|
+
end
|
175
|
+
|
176
|
+
def self.GetContinents(
|
177
|
+
key:
|
178
|
+
)
|
179
|
+
params = {
|
180
|
+
}
|
181
|
+
items = CallAPI('continents', params, key)
|
182
|
+
return items
|
183
|
+
end
|
184
|
+
|
185
|
+
def self.GetContinent(
|
186
|
+
key:,
|
187
|
+
id: 0,
|
188
|
+
name: nil
|
189
|
+
)
|
190
|
+
params = {
|
191
|
+
:id => id,
|
192
|
+
:name => name
|
193
|
+
}
|
194
|
+
items = CallAPI('continents', params, key)
|
195
|
+
if items.length() == 0
|
196
|
+
raise Exception.new "API error: item not found"
|
197
|
+
end
|
198
|
+
return items[0]
|
199
|
+
end
|
200
|
+
|
201
|
+
def self.GetCountries(
|
202
|
+
key:,
|
203
|
+
continentId: nil,
|
204
|
+
continent: nil
|
205
|
+
)
|
206
|
+
params = {
|
207
|
+
:continentId => continentId,
|
208
|
+
:continent => continent,
|
209
|
+
}
|
210
|
+
items = CallAPI('countries', params, key)
|
211
|
+
return items
|
212
|
+
end
|
213
|
+
|
214
|
+
def self.GetCountry(
|
215
|
+
key:,
|
216
|
+
id: 0,
|
217
|
+
name: nil
|
218
|
+
)
|
219
|
+
params = {
|
220
|
+
:id => id,
|
221
|
+
:name => name
|
222
|
+
}
|
223
|
+
items = CallAPI('countries', params, key)
|
224
|
+
if items.length() == 0
|
225
|
+
raise Exception.new "API error: item not found"
|
226
|
+
end
|
227
|
+
return items[0]
|
228
|
+
end
|
229
|
+
|
230
|
+
def self.GetRegions(
|
231
|
+
key:,
|
232
|
+
countryId: nil,
|
233
|
+
country: nil,
|
234
|
+
continentId: nil,
|
235
|
+
continent: nil
|
236
|
+
)
|
237
|
+
params = {
|
238
|
+
:countryId => countryId,
|
239
|
+
:country => country,
|
240
|
+
:continentId => continentId,
|
241
|
+
:continent => continent,
|
242
|
+
}
|
243
|
+
items = CallAPI('regions', params, key)
|
244
|
+
return items
|
245
|
+
end
|
246
|
+
|
247
|
+
def self.GetRegion(
|
248
|
+
key:,
|
249
|
+
id: 0,
|
250
|
+
name: nil
|
251
|
+
)
|
252
|
+
params = {
|
253
|
+
:id => id,
|
254
|
+
:name => name
|
255
|
+
}
|
256
|
+
items = CallAPI('regions', params, key)
|
257
|
+
if items.length() == 0
|
258
|
+
raise Exception.new "API error: item not found"
|
259
|
+
end
|
260
|
+
return items[0]
|
261
|
+
end
|
262
|
+
|
263
|
+
def self.GetLocations(
|
264
|
+
key:,
|
265
|
+
countryId: nil,
|
266
|
+
country: nil,
|
267
|
+
regionId: nil,
|
268
|
+
region: nil
|
269
|
+
)
|
270
|
+
params = {
|
271
|
+
:countryId => countryId,
|
272
|
+
:country => country,
|
273
|
+
:regionId => regionId,
|
274
|
+
:region => region,
|
275
|
+
}
|
276
|
+
items = CallAPI('locations', params, key)
|
277
|
+
return items
|
278
|
+
end
|
279
|
+
|
280
|
+
def self.GetLocation(
|
281
|
+
key:,
|
282
|
+
id: 0,
|
283
|
+
name: nil,
|
284
|
+
countryId: nil,
|
285
|
+
country: nil,
|
286
|
+
regionId: nil,
|
287
|
+
region: nil
|
288
|
+
)
|
289
|
+
params = {
|
290
|
+
:id => id,
|
291
|
+
:name => name,
|
292
|
+
:countryId => countryId,
|
293
|
+
:country => country,
|
294
|
+
:regionId => regionId,
|
295
|
+
:region => region,
|
296
|
+
}
|
297
|
+
items = CallAPI('locations', params, key)
|
298
|
+
if items.length() > 1
|
299
|
+
raise Exception.new "API error: multiple items found (#{items.length()}). Provide countryId, country, regionId or region."
|
300
|
+
end
|
301
|
+
if items.length() == 0
|
302
|
+
raise Exception.new "API error: item not found"
|
303
|
+
end
|
304
|
+
return items[0]
|
305
|
+
end
|
306
|
+
end
|
metadata
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: AllSportDB
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- AllSportDB.com
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2022-04-05 00:00:00.000000000 Z
|
12
|
+
dependencies: []
|
13
|
+
description: AllSportDB API
|
14
|
+
email: feedback@allsportdb.com
|
15
|
+
executables: []
|
16
|
+
extensions: []
|
17
|
+
extra_rdoc_files: []
|
18
|
+
files:
|
19
|
+
- lib/allsportdb_api.rb
|
20
|
+
homepage: https://allsportdb.com/api
|
21
|
+
licenses:
|
22
|
+
- MIT
|
23
|
+
metadata: {}
|
24
|
+
post_install_message:
|
25
|
+
rdoc_options: []
|
26
|
+
require_paths:
|
27
|
+
- lib
|
28
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
29
|
+
requirements:
|
30
|
+
- - ">="
|
31
|
+
- !ruby/object:Gem::Version
|
32
|
+
version: '0'
|
33
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
34
|
+
requirements:
|
35
|
+
- - ">="
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: '0'
|
38
|
+
requirements: []
|
39
|
+
rubygems_version: 3.3.8
|
40
|
+
signing_key:
|
41
|
+
specification_version: 4
|
42
|
+
summary: AllSportDB API
|
43
|
+
test_files: []
|