api-sports 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.rspec +3 -0
- data/.rubocop.yml +236 -0
- data/Gemfile +12 -0
- data/Gemfile.lock +63 -0
- data/LICENSE +21 -0
- data/README.md +65 -0
- data/Rakefile +12 -0
- data/lib/api_sports/client.rb +65 -0
- data/lib/api_sports/collection.rb +24 -0
- data/lib/api_sports/error.rb +6 -0
- data/lib/api_sports/object.rb +26 -0
- data/lib/api_sports/objects/bet.rb +6 -0
- data/lib/api_sports/objects/bookmaker.rb +6 -0
- data/lib/api_sports/objects/country.rb +6 -0
- data/lib/api_sports/objects/event.rb +6 -0
- data/lib/api_sports/objects/fixture.rb +6 -0
- data/lib/api_sports/objects/fixture_round.rb +9 -0
- data/lib/api_sports/objects/league.rb +6 -0
- data/lib/api_sports/objects/lineup.rb +6 -0
- data/lib/api_sports/objects/odds.rb +6 -0
- data/lib/api_sports/objects/player.rb +6 -0
- data/lib/api_sports/objects/prediction.rb +6 -0
- data/lib/api_sports/objects/season.rb +9 -0
- data/lib/api_sports/objects/standing.rb +6 -0
- data/lib/api_sports/objects/statistics.rb +6 -0
- data/lib/api_sports/objects/team.rb +6 -0
- data/lib/api_sports/objects/timezone.rb +9 -0
- data/lib/api_sports/objects/venue.rb +6 -0
- data/lib/api_sports/resource.rb +30 -0
- data/lib/api_sports/resources/countries.rb +10 -0
- data/lib/api_sports/resources/fixtures.rb +43 -0
- data/lib/api_sports/resources/leagues.rb +23 -0
- data/lib/api_sports/resources/odds.rb +39 -0
- data/lib/api_sports/resources/standings.rb +15 -0
- data/lib/api_sports/resources/teams.rb +27 -0
- data/lib/api_sports/resources/timezones.rb +10 -0
- data/lib/api_sports/resources/venues.rb +12 -0
- data/lib/api_sports/version.rb +5 -0
- data/lib/api_sports.rb +43 -0
- metadata +98 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 8234cba5149ee13f90f848f17a3f02d04f503474e24af99879867940da54c77b
|
4
|
+
data.tar.gz: d184b77cb1ab72188b09fa7a03f2fec38242119fe446eeb6b7cb3413a644a547
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 3dfdacbe4e256c46f40f957dadb468b244b98b69a6068e268f55eea0dc1f4df2890675b53055bb8411911a3c89d01a89445473178019de54aaee9218384e9124
|
7
|
+
data.tar.gz: 8d1ed792973e3f033fcde3e52de09967b7905931ee2fe0fffb87348cac689c3392310c9b4e61e67b4efba9247d9058e1f43b06aa815442136bb8f09b6596d078
|
data/.rspec
ADDED
data/.rubocop.yml
ADDED
@@ -0,0 +1,236 @@
|
|
1
|
+
AllCops:
|
2
|
+
TargetRubyVersion: 2.7
|
3
|
+
# RuboCop has a bunch of cops enabled by default. This setting tells RuboCop
|
4
|
+
# to ignore them, so only the ones explicitly set in this file are enabled.
|
5
|
+
DisabledByDefault: true
|
6
|
+
SuggestExtensions: false
|
7
|
+
|
8
|
+
# Prefer &&/|| over and/or.
|
9
|
+
Style/AndOr:
|
10
|
+
Enabled: true
|
11
|
+
|
12
|
+
# Align `when` with `case`.
|
13
|
+
Layout/CaseIndentation:
|
14
|
+
Enabled: true
|
15
|
+
|
16
|
+
Layout/ClosingHeredocIndentation:
|
17
|
+
Enabled: true
|
18
|
+
|
19
|
+
Layout/ClosingParenthesisIndentation:
|
20
|
+
Enabled: true
|
21
|
+
|
22
|
+
# Align comments with method definitions.
|
23
|
+
Layout/CommentIndentation:
|
24
|
+
Enabled: true
|
25
|
+
|
26
|
+
Layout/ElseAlignment:
|
27
|
+
Enabled: true
|
28
|
+
|
29
|
+
# Align `end` with the matching keyword or starting expression except for
|
30
|
+
# assignments, where it should be aligned with the LHS.
|
31
|
+
Layout/EndAlignment:
|
32
|
+
Enabled: true
|
33
|
+
EnforcedStyleAlignWith: variable
|
34
|
+
AutoCorrect: true
|
35
|
+
|
36
|
+
Layout/EndOfLine:
|
37
|
+
Enabled: true
|
38
|
+
|
39
|
+
Layout/EmptyLineAfterMagicComment:
|
40
|
+
Enabled: true
|
41
|
+
|
42
|
+
Layout/EmptyLinesAroundAccessModifier:
|
43
|
+
Enabled: true
|
44
|
+
EnforcedStyle: only_before
|
45
|
+
|
46
|
+
Layout/EmptyLinesAroundBlockBody:
|
47
|
+
Enabled: true
|
48
|
+
|
49
|
+
# In a regular class definition, no empty lines around the body.
|
50
|
+
Layout/EmptyLinesAroundClassBody:
|
51
|
+
Enabled: true
|
52
|
+
|
53
|
+
# In a regular method definition, no empty lines around the body.
|
54
|
+
Layout/EmptyLinesAroundMethodBody:
|
55
|
+
Enabled: true
|
56
|
+
|
57
|
+
# In a regular module definition, no empty lines around the body.
|
58
|
+
Layout/EmptyLinesAroundModuleBody:
|
59
|
+
Enabled: true
|
60
|
+
|
61
|
+
# Use Ruby >= 1.9 syntax for hashes. Prefer { a: :b } over { :a => :b }.
|
62
|
+
Style/HashSyntax:
|
63
|
+
Enabled: true
|
64
|
+
|
65
|
+
# Method definitions after `private` or `protected` isolated calls need one
|
66
|
+
# extra level of indentation.
|
67
|
+
Layout/IndentationConsistency:
|
68
|
+
Enabled: true
|
69
|
+
EnforcedStyle: indented_internal_methods
|
70
|
+
|
71
|
+
# Two spaces, no tabs (for indentation).
|
72
|
+
Layout/IndentationWidth:
|
73
|
+
Enabled: true
|
74
|
+
|
75
|
+
Layout/LeadingCommentSpace:
|
76
|
+
Enabled: true
|
77
|
+
|
78
|
+
Layout/SpaceAfterColon:
|
79
|
+
Enabled: true
|
80
|
+
|
81
|
+
Layout/SpaceAfterComma:
|
82
|
+
Enabled: true
|
83
|
+
|
84
|
+
Layout/SpaceAfterSemicolon:
|
85
|
+
Enabled: true
|
86
|
+
|
87
|
+
Layout/SpaceAroundEqualsInParameterDefault:
|
88
|
+
Enabled: true
|
89
|
+
|
90
|
+
Layout/SpaceAroundKeyword:
|
91
|
+
Enabled: true
|
92
|
+
|
93
|
+
Layout/SpaceAroundOperators:
|
94
|
+
Enabled: true
|
95
|
+
|
96
|
+
Layout/SpaceBeforeComma:
|
97
|
+
Enabled: true
|
98
|
+
|
99
|
+
Layout/SpaceBeforeComment:
|
100
|
+
Enabled: true
|
101
|
+
|
102
|
+
Layout/SpaceBeforeFirstArg:
|
103
|
+
Enabled: true
|
104
|
+
|
105
|
+
Style/DefWithParentheses:
|
106
|
+
Enabled: true
|
107
|
+
|
108
|
+
# Defining a method with parameters needs parentheses.
|
109
|
+
Style/MethodDefParentheses:
|
110
|
+
Enabled: true
|
111
|
+
|
112
|
+
Style/ExplicitBlockArgument:
|
113
|
+
Enabled: true
|
114
|
+
|
115
|
+
Style/FrozenStringLiteralComment:
|
116
|
+
Enabled: true
|
117
|
+
EnforcedStyle: always
|
118
|
+
|
119
|
+
Style/MapToHash:
|
120
|
+
Enabled: true
|
121
|
+
|
122
|
+
Style/RedundantFreeze:
|
123
|
+
Enabled: true
|
124
|
+
|
125
|
+
# Use `foo {}` not `foo{}`.
|
126
|
+
Layout/SpaceBeforeBlockBraces:
|
127
|
+
Enabled: true
|
128
|
+
|
129
|
+
# Use `foo { bar }` not `foo {bar}`.
|
130
|
+
Layout/SpaceInsideBlockBraces:
|
131
|
+
Enabled: true
|
132
|
+
EnforcedStyleForEmptyBraces: space
|
133
|
+
|
134
|
+
# Use `{ a: 1 }` not `{a:1}`.
|
135
|
+
Layout/SpaceInsideHashLiteralBraces:
|
136
|
+
Enabled: true
|
137
|
+
|
138
|
+
Layout/SpaceInsideParens:
|
139
|
+
Enabled: true
|
140
|
+
|
141
|
+
# Check quotes usage according to lint rule below.
|
142
|
+
Style/StringLiterals:
|
143
|
+
Enabled: true
|
144
|
+
EnforcedStyle: double_quotes
|
145
|
+
|
146
|
+
# Detect hard tabs, no hard tabs.
|
147
|
+
Layout/IndentationStyle:
|
148
|
+
Enabled: true
|
149
|
+
|
150
|
+
# Empty lines should not have any spaces.
|
151
|
+
Layout/TrailingEmptyLines:
|
152
|
+
Enabled: true
|
153
|
+
|
154
|
+
# No trailing whitespace.
|
155
|
+
Layout/TrailingWhitespace:
|
156
|
+
Enabled: true
|
157
|
+
|
158
|
+
# Use quotes for string literals when they are enough.
|
159
|
+
Style/RedundantPercentQ:
|
160
|
+
Enabled: true
|
161
|
+
|
162
|
+
Lint/AmbiguousOperator:
|
163
|
+
Enabled: true
|
164
|
+
|
165
|
+
Lint/AmbiguousRegexpLiteral:
|
166
|
+
Enabled: true
|
167
|
+
|
168
|
+
Lint/DuplicateRequire:
|
169
|
+
Enabled: true
|
170
|
+
|
171
|
+
Lint/DuplicateMagicComment:
|
172
|
+
Enabled: true
|
173
|
+
|
174
|
+
Lint/DuplicateMethods:
|
175
|
+
Enabled: true
|
176
|
+
|
177
|
+
Lint/ErbNewArguments:
|
178
|
+
Enabled: true
|
179
|
+
|
180
|
+
Lint/EnsureReturn:
|
181
|
+
Enabled: true
|
182
|
+
|
183
|
+
# Use my_method(my_arg) not my_method( my_arg ) or my_method my_arg.
|
184
|
+
Lint/RequireParentheses:
|
185
|
+
Enabled: true
|
186
|
+
|
187
|
+
Lint/RedundantStringCoercion:
|
188
|
+
Enabled: true
|
189
|
+
|
190
|
+
Lint/UriEscapeUnescape:
|
191
|
+
Enabled: true
|
192
|
+
|
193
|
+
Lint/UselessAssignment:
|
194
|
+
Enabled: true
|
195
|
+
|
196
|
+
Lint/DeprecatedClassMethods:
|
197
|
+
Enabled: true
|
198
|
+
|
199
|
+
Style/EvalWithLocation:
|
200
|
+
Enabled: true
|
201
|
+
Exclude:
|
202
|
+
- "**/test/**/*"
|
203
|
+
|
204
|
+
Style/ParenthesesAroundCondition:
|
205
|
+
Enabled: true
|
206
|
+
|
207
|
+
Style/HashTransformKeys:
|
208
|
+
Enabled: true
|
209
|
+
|
210
|
+
Style/HashTransformValues:
|
211
|
+
Enabled: true
|
212
|
+
|
213
|
+
Style/RedundantBegin:
|
214
|
+
Enabled: true
|
215
|
+
|
216
|
+
Style/RedundantReturn:
|
217
|
+
Enabled: true
|
218
|
+
AllowMultipleReturnValues: true
|
219
|
+
|
220
|
+
Style/RedundantRegexpEscape:
|
221
|
+
Enabled: true
|
222
|
+
|
223
|
+
Style/Semicolon:
|
224
|
+
Enabled: true
|
225
|
+
AllowAsExpressionSeparator: true
|
226
|
+
|
227
|
+
# Prefer Foo.method over Foo::method
|
228
|
+
Style/ColonMethodCall:
|
229
|
+
Enabled: true
|
230
|
+
|
231
|
+
Style/TrivialAccessors:
|
232
|
+
Enabled: true
|
233
|
+
|
234
|
+
# Prefer a = b || c over a = b ? b : c
|
235
|
+
Style/RedundantCondition:
|
236
|
+
Enabled: true
|
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,63 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
api_sports (0.1.0)
|
5
|
+
faraday (~> 2.7)
|
6
|
+
|
7
|
+
GEM
|
8
|
+
remote: https://rubygems.org/
|
9
|
+
specs:
|
10
|
+
ast (2.4.2)
|
11
|
+
diff-lcs (1.5.0)
|
12
|
+
faraday (2.7.4)
|
13
|
+
faraday-net_http (>= 2.0, < 3.1)
|
14
|
+
ruby2_keywords (>= 0.0.4)
|
15
|
+
faraday-net_http (3.0.2)
|
16
|
+
json (2.6.3)
|
17
|
+
parallel (1.22.1)
|
18
|
+
parser (3.2.1.1)
|
19
|
+
ast (~> 2.4.1)
|
20
|
+
rainbow (3.1.1)
|
21
|
+
rake (13.0.6)
|
22
|
+
regexp_parser (2.7.0)
|
23
|
+
rexml (3.2.5)
|
24
|
+
rspec (3.12.0)
|
25
|
+
rspec-core (~> 3.12.0)
|
26
|
+
rspec-expectations (~> 3.12.0)
|
27
|
+
rspec-mocks (~> 3.12.0)
|
28
|
+
rspec-core (3.12.1)
|
29
|
+
rspec-support (~> 3.12.0)
|
30
|
+
rspec-expectations (3.12.2)
|
31
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
32
|
+
rspec-support (~> 3.12.0)
|
33
|
+
rspec-mocks (3.12.4)
|
34
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
35
|
+
rspec-support (~> 3.12.0)
|
36
|
+
rspec-support (3.12.0)
|
37
|
+
rubocop (1.48.1)
|
38
|
+
json (~> 2.3)
|
39
|
+
parallel (~> 1.10)
|
40
|
+
parser (>= 3.2.0.0)
|
41
|
+
rainbow (>= 2.2.2, < 4.0)
|
42
|
+
regexp_parser (>= 1.8, < 3.0)
|
43
|
+
rexml (>= 3.2.5, < 4.0)
|
44
|
+
rubocop-ast (>= 1.26.0, < 2.0)
|
45
|
+
ruby-progressbar (~> 1.7)
|
46
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
47
|
+
rubocop-ast (1.27.0)
|
48
|
+
parser (>= 3.2.1.0)
|
49
|
+
ruby-progressbar (1.13.0)
|
50
|
+
ruby2_keywords (0.0.5)
|
51
|
+
unicode-display_width (2.4.2)
|
52
|
+
|
53
|
+
PLATFORMS
|
54
|
+
x86_64-darwin-22
|
55
|
+
|
56
|
+
DEPENDENCIES
|
57
|
+
api_sports!
|
58
|
+
rake (~> 13.0)
|
59
|
+
rspec (~> 3.0)
|
60
|
+
rubocop (~> 1.21)
|
61
|
+
|
62
|
+
BUNDLED WITH
|
63
|
+
2.4.5
|
data/LICENSE
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
MIT License
|
2
|
+
|
3
|
+
Copyright (c) [2023] [Bryan Byrne]
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
13
|
+
copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
21
|
+
SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# ApiSports API Rubygem [BETA]
|
2
|
+
|
3
|
+
An unofficial ruby gem to integrate [API-Sports](https://api-sports.io/#) sports data into your app.
|
4
|
+
|
5
|
+
[API-Sports](https://api-sports.io/) provides sports data APIs. This gem is an unofficial wrapper providing lightweight integration of sports data into an application or service. This library does not attempt to support all API capabilities but instead focuses on the most used endpoints (e.g. retrieving game data). Coverage summary:
|
6
|
+
|
7
|
+
| Sport | API-Sports Documentation | Library Support |
|
8
|
+
| :---------------------- | :----------------------------------------------------------------------- | :----------------- |
|
9
|
+
| Football/Soccer | [API-Football Docs](https://api-sports.io/documentation/football/v3) | :white_check_mark: |
|
10
|
+
| Basketball | [API-Basketball Docs](https://api-sports.io/documentation/basketball/v1) | :construction: |
|
11
|
+
| American Football (NFL) | [API-NFL Docs](https://api-sports.io/documentation/nfl/v1) | :construction: |
|
12
|
+
|
13
|
+
## Installation
|
14
|
+
|
15
|
+
Install the gem and add to the application's Gemfile by executing:
|
16
|
+
|
17
|
+
$ bundle add api-sports
|
18
|
+
|
19
|
+
If bundler is not being used to manage dependencies, install the gem by executing:
|
20
|
+
|
21
|
+
$ gem install api-sports
|
22
|
+
|
23
|
+
## Usage
|
24
|
+
|
25
|
+
**Prerequisite:** Set an environment variable `API_SPORTS_KEY` that contains the API key provided by [API-Sports](https://api-sports.io).
|
26
|
+
|
27
|
+
```ruby
|
28
|
+
client = ApiSports::Client.new(api_key: ENV["API_SPORTS_KEY"])
|
29
|
+
|
30
|
+
# client has a reference to instances of resource objects corresponding API endpoints
|
31
|
+
# e.g. client.leagues will access `/leagues` endpoint data.
|
32
|
+
# e.g. client.fixtures will access `/fixtures` endpoint data.
|
33
|
+
# etc.
|
34
|
+
# Parameters can be passed as needed to respective methods.
|
35
|
+
fixtures = client.fixtures.list(
|
36
|
+
league: 39, # Premier League
|
37
|
+
season: 2022,
|
38
|
+
date: "2022-09-03",
|
39
|
+
status: "FT"
|
40
|
+
)
|
41
|
+
|
42
|
+
# Additional resources (e.g. `/fixtures/lineups`) can be accessed
|
43
|
+
# by chaining the method calls. For clarify required parameters have been
|
44
|
+
# identified and made required paremeters when possible (additional parameters may be passed also)
|
45
|
+
fixtures = client.fixtures.head_to_head(first_team_id: 33, second_team_id: 34)
|
46
|
+
|
47
|
+
# Responses will include pagination information included in `paging` attribute of API responses
|
48
|
+
fixtures.total
|
49
|
+
fixtures.current_page
|
50
|
+
fixtures.total_pages
|
51
|
+
```
|
52
|
+
|
53
|
+
## Acknowledgements
|
54
|
+
|
55
|
+
Hat tip to [tolbkni](vultr.rb) and [GoRails](https://gorails.com/episodes/api-requests-with-faraday) for inspiration on how to structure this library.
|
56
|
+
|
57
|
+
## Development
|
58
|
+
|
59
|
+
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
60
|
+
|
61
|
+
To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and the created tag, and push the `.gem` file to [rubygems.org](https://rubygems.org).
|
62
|
+
|
63
|
+
## Contributing
|
64
|
+
|
65
|
+
Bug reports and pull requests are welcome on GitHub at https://github.com/irishbryan/api_sports.
|
data/Rakefile
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiSports
|
4
|
+
class Client
|
5
|
+
BASE_URL = "https://v3.football.api-sports.io/"
|
6
|
+
|
7
|
+
attr_reader :api_key, :adapter
|
8
|
+
|
9
|
+
def initialize(api_key:, adapter: Faraday.default_adapter, stubs: nil)
|
10
|
+
@api_key = api_key
|
11
|
+
@adapter = adapter
|
12
|
+
|
13
|
+
# Test stubs for requests
|
14
|
+
@stubs = stubs
|
15
|
+
end
|
16
|
+
|
17
|
+
def countries
|
18
|
+
CountriesResource.new(self)
|
19
|
+
end
|
20
|
+
|
21
|
+
def timezones
|
22
|
+
TimezonesResource.new(self)
|
23
|
+
end
|
24
|
+
|
25
|
+
def leagues
|
26
|
+
LeaguesResource.new(self)
|
27
|
+
end
|
28
|
+
|
29
|
+
def seasons
|
30
|
+
SeasonsResource.new(self)
|
31
|
+
end
|
32
|
+
|
33
|
+
def teams
|
34
|
+
TeamsResource.new(self)
|
35
|
+
end
|
36
|
+
|
37
|
+
def venues
|
38
|
+
VenuesResource.new(self)
|
39
|
+
end
|
40
|
+
|
41
|
+
def standings
|
42
|
+
StandingsResource.new(self)
|
43
|
+
end
|
44
|
+
|
45
|
+
def fixtures
|
46
|
+
FixturesResource.new(self)
|
47
|
+
end
|
48
|
+
|
49
|
+
def predictions
|
50
|
+
PredictionsResource.new(self)
|
51
|
+
end
|
52
|
+
|
53
|
+
def odds
|
54
|
+
OddsResource.new(self)
|
55
|
+
end
|
56
|
+
|
57
|
+
def connection
|
58
|
+
@connection ||= Faraday.new(BASE_URL) do |conn|
|
59
|
+
conn.headers = { "x-apisports-key": api_key }
|
60
|
+
conn.response :json, content_type: "application/json"
|
61
|
+
conn.adapter adapter, @stubs
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiSports
|
4
|
+
class Collection
|
5
|
+
attr_reader :data, :total, :current_page, :total_pages
|
6
|
+
|
7
|
+
def self.from_response(response, type:, &block)
|
8
|
+
body = response.body
|
9
|
+
new(
|
10
|
+
data: block.nil? ? body["response"].map { |attrs| type.new(attrs) } : yield(body),
|
11
|
+
total: body["results"],
|
12
|
+
current_page: body["paging"]["current"],
|
13
|
+
total_pages: body["paging"]["total"]
|
14
|
+
)
|
15
|
+
end
|
16
|
+
|
17
|
+
def initialize(data:, total:, current_page:, total_pages:)
|
18
|
+
@data = data
|
19
|
+
@total = total
|
20
|
+
@current_page = current_page
|
21
|
+
@total_pages = total_pages
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "ostruct"
|
4
|
+
|
5
|
+
module ApiSports
|
6
|
+
# Class to make access to response data easier
|
7
|
+
# e.g. response.name instead of response['name']
|
8
|
+
# Inspired by https://github.com/tolbkni/vultr.rb
|
9
|
+
# and https://gorails.com/episodes/api-requests-with-faraday
|
10
|
+
|
11
|
+
class Object < OpenStruct
|
12
|
+
def initialize(attributes)
|
13
|
+
super to_ostruct(attributes)
|
14
|
+
end
|
15
|
+
|
16
|
+
def to_ostruct(obj)
|
17
|
+
if obj.is_a?(Hash)
|
18
|
+
OpenStruct.new(obj.transform_values { | value | to_ostruct(value) })
|
19
|
+
elsif obj.is_a?(Array)
|
20
|
+
obj.map { |o| to_ostruct(o) }
|
21
|
+
else
|
22
|
+
obj # Assumed to be primitive type
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiSports
|
4
|
+
class Resource
|
5
|
+
attr_reader :client
|
6
|
+
|
7
|
+
def initialize(client)
|
8
|
+
@client = client
|
9
|
+
end
|
10
|
+
|
11
|
+
def get_request(url, params: {}, headers: {})
|
12
|
+
handle_response client.connection.get(url, params, headers)
|
13
|
+
end
|
14
|
+
|
15
|
+
def get_single_resource(url, params: {}, headers: {}, &dig_block)
|
16
|
+
response = get_request(url, params: params, headers: headers)
|
17
|
+
yield(response)
|
18
|
+
end
|
19
|
+
|
20
|
+
def handle_response(response)
|
21
|
+
errors = response.body["errors"]
|
22
|
+
|
23
|
+
if errors.empty?
|
24
|
+
response
|
25
|
+
else
|
26
|
+
raise Error, errors
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiSports
|
4
|
+
class FixturesResource < Resource
|
5
|
+
def list(**params)
|
6
|
+
response = get_request("fixtures", params: params)
|
7
|
+
Collection.from_response(response, type: Fixture)
|
8
|
+
end
|
9
|
+
|
10
|
+
def rounds(league_id:, season_id:, current_round_only: false)
|
11
|
+
response = get_request("fixtures/rounds",
|
12
|
+
params: { league: league_id,
|
13
|
+
season: season_id,
|
14
|
+
current: current_round_only }.compact)
|
15
|
+
Collection.from_response(response, type: FixtureRound)
|
16
|
+
end
|
17
|
+
|
18
|
+
def head_to_head(first_team_id:, second_team_id:, **params)
|
19
|
+
response = get_request("fixtures/headtohead", params: { h2h: "#{first_team_id}-#{second_team_id}" }.merge(params))
|
20
|
+
Collection.from_response(response, type: Fixture)
|
21
|
+
end
|
22
|
+
|
23
|
+
def statistics(fixture_id:, **params)
|
24
|
+
response = get_request("fixtures/statistics", params: { fixture: fixture_id }.merge(params))
|
25
|
+
Collection.from_response(response, type: Statistics)
|
26
|
+
end
|
27
|
+
|
28
|
+
def events(fixture_id:, **params)
|
29
|
+
response = get_request("fixtures/events", params: { fixture: fixture_id }.merge(params))
|
30
|
+
Collection.from_response(response, type: Event)
|
31
|
+
end
|
32
|
+
|
33
|
+
def lineups(fixture_id:, **params)
|
34
|
+
response = get_request("fixtures/lineups", params: { fixture: fixture_id }.merge(params))
|
35
|
+
Collection.from_response(response, type: Lineup)
|
36
|
+
end
|
37
|
+
|
38
|
+
def player_statistics(fixture_id:, **params)
|
39
|
+
response = get_request("fixtures/players", params: { fixture: fixture_id }.merge(params))
|
40
|
+
Collection.from_response(response, type: Player)
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiSports
|
4
|
+
class LeaguesResource < Resource
|
5
|
+
def list(**params)
|
6
|
+
response = get_request("leagues", params: params)
|
7
|
+
Collection.from_response(response, type: League)
|
8
|
+
end
|
9
|
+
|
10
|
+
def retrieve(league_id:)
|
11
|
+
response = get_single_resource("leagues", params: { id: league_id }) do |r|
|
12
|
+
r.body["response"].first.dig("league")
|
13
|
+
end
|
14
|
+
League.new(response)
|
15
|
+
end
|
16
|
+
|
17
|
+
def seasons
|
18
|
+
response = get_request("leagues/seasons")
|
19
|
+
Collection.from_response(response, type: Season)
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiSports
|
4
|
+
class OddsResource < Resource
|
5
|
+
def pre_match_odds(fixture_id:, bookmaker_id: nil, **params)
|
6
|
+
response = get_request("odds",
|
7
|
+
params: { fixture: fixture_id,
|
8
|
+
bookmaker: bookmaker_id }.compact.merge(params))
|
9
|
+
Collection.from_response(response, type: Odds)
|
10
|
+
end
|
11
|
+
|
12
|
+
def mapping(**params)
|
13
|
+
response = get_request("odds/mapping", params: params)
|
14
|
+
Collection.from_response(response, type: Fixture)
|
15
|
+
end
|
16
|
+
|
17
|
+
def bookmakers
|
18
|
+
response = get_request("odds/bookmakers")
|
19
|
+
Collection.from_response(response, type: Bookmaker)
|
20
|
+
end
|
21
|
+
|
22
|
+
def pre_match_bets
|
23
|
+
response = get_request("odds/bets")
|
24
|
+
Collection.from_response(response, type: Bet)
|
25
|
+
end
|
26
|
+
|
27
|
+
def live_odds(fixture_id:, bookmaker_id: nil, **params)
|
28
|
+
response = get_request("odds/live",
|
29
|
+
params: { fixture: fixture_id,
|
30
|
+
bookmaker: bookmaker_id }.compact.merge(params))
|
31
|
+
Collection.from_response(response, type: Odds)
|
32
|
+
end
|
33
|
+
|
34
|
+
def live_bets
|
35
|
+
response = get_request("odds/live/bets")
|
36
|
+
Collection.from_response(response, type: Bet)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiSports
|
4
|
+
class StandingsResource < Resource
|
5
|
+
def retrieve(league_id:, season_id: nil, team_id: nil)
|
6
|
+
response = get_request("standings",
|
7
|
+
params: { league: league_id,
|
8
|
+
season: season_id,
|
9
|
+
team: team_id }.compact)
|
10
|
+
Collection.from_response(response, type: Standing) do |body|
|
11
|
+
body["response"].first["league"]["standings"].first.map { |attrs| Standing.new(attrs) }
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
module ApiSports
|
4
|
+
class TeamsResource < Resource
|
5
|
+
def list(**params)
|
6
|
+
response = get_request("teams", params: params)
|
7
|
+
Collection.from_response(response, type: Team)
|
8
|
+
end
|
9
|
+
|
10
|
+
def retrieve(team_id:)
|
11
|
+
response = get_single_resource("teams", params: { id: team_id }) do |r|
|
12
|
+
r.body["response"].first.dig("team")
|
13
|
+
end
|
14
|
+
Team.new(response)
|
15
|
+
end
|
16
|
+
|
17
|
+
def statistics(league_id:, season_id:, team_id:)
|
18
|
+
response = get_request("teams/statistics", params: { team: team_id, league: league_id, season: season_id })
|
19
|
+
Statistics.new(response.body["response"])
|
20
|
+
end
|
21
|
+
|
22
|
+
def seasons(team_id:)
|
23
|
+
response = get_request("teams/seasons", params: { team: team_id })
|
24
|
+
Collection.from_response(response, type: Season)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
data/lib/api_sports.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
# frozen_string_literal: true
|
2
|
+
|
3
|
+
require "faraday"
|
4
|
+
require_relative "api_sports/version"
|
5
|
+
|
6
|
+
module ApiSports
|
7
|
+
autoload :Client, "api_sports/client"
|
8
|
+
autoload :Object, "api_sports/object"
|
9
|
+
autoload :Collection, "api_sports/collection"
|
10
|
+
autoload :Error, "api_sports/error"
|
11
|
+
autoload :Resource, "api_sports/resource"
|
12
|
+
|
13
|
+
# Classes used to return a nicer object wrapping the response data
|
14
|
+
autoload :Country, "api_sports/objects/country"
|
15
|
+
autoload :Timezone, "api_sports/objects/timezone"
|
16
|
+
autoload :League, "api_sports/objects/league"
|
17
|
+
autoload :Season, "api_sports/objects/season"
|
18
|
+
autoload :Team, "api_sports/objects/team"
|
19
|
+
autoload :Venue, "api_sports/objects/venue"
|
20
|
+
autoload :Statistics, "api_sports/objects/statistics"
|
21
|
+
autoload :Standing, "api_sports/objects/standing"
|
22
|
+
autoload :Fixture, "api_sports/objects/fixture"
|
23
|
+
autoload :Event, "api_sports/objects/event"
|
24
|
+
autoload :Lineup, "api_sports/objects/lineup"
|
25
|
+
autoload :Player, "api_sports/objects/player"
|
26
|
+
autoload :FixtureRound, "api_sports/objects/fixture_round"
|
27
|
+
autoload :Prediction, "api_sports/objects/prediction"
|
28
|
+
autoload :Bookmaker, "api_sports/objects/bookmaker"
|
29
|
+
autoload :Odds, "api_sports/objects/odds"
|
30
|
+
autoload :Bet, "api_sports/objects/bet"
|
31
|
+
|
32
|
+
# Category of API calls
|
33
|
+
autoload :CountriesResource, "api_sports/resources/countries"
|
34
|
+
autoload :TimezonesResource, "api_sports/resources/timezones"
|
35
|
+
autoload :LeaguesResource, "api_sports/resources/leagues"
|
36
|
+
autoload :SeasonsResource, "api_sports/resources/seasons"
|
37
|
+
autoload :TeamsResource, "api_sports/resources/teams"
|
38
|
+
autoload :VenuesResource, "api_sports/resources/venues"
|
39
|
+
autoload :StandingsResource, "api_sports/resources/standings"
|
40
|
+
autoload :FixturesResource, "api_sports/resources/fixtures"
|
41
|
+
autoload :PredictionsResource, "api_sports/resources/predictions"
|
42
|
+
autoload :OddsResource, "api_sports/resources/odds"
|
43
|
+
end
|
metadata
ADDED
@@ -0,0 +1,98 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: api-sports
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- irishbryan
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2023-03-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: faraday
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.7'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.7'
|
27
|
+
description:
|
28
|
+
email:
|
29
|
+
- bbyrne@gmail.com
|
30
|
+
executables: []
|
31
|
+
extensions: []
|
32
|
+
extra_rdoc_files: []
|
33
|
+
files:
|
34
|
+
- ".rspec"
|
35
|
+
- ".rubocop.yml"
|
36
|
+
- Gemfile
|
37
|
+
- Gemfile.lock
|
38
|
+
- LICENSE
|
39
|
+
- README.md
|
40
|
+
- Rakefile
|
41
|
+
- lib/api_sports.rb
|
42
|
+
- lib/api_sports/client.rb
|
43
|
+
- lib/api_sports/collection.rb
|
44
|
+
- lib/api_sports/error.rb
|
45
|
+
- lib/api_sports/object.rb
|
46
|
+
- lib/api_sports/objects/bet.rb
|
47
|
+
- lib/api_sports/objects/bookmaker.rb
|
48
|
+
- lib/api_sports/objects/country.rb
|
49
|
+
- lib/api_sports/objects/event.rb
|
50
|
+
- lib/api_sports/objects/fixture.rb
|
51
|
+
- lib/api_sports/objects/fixture_round.rb
|
52
|
+
- lib/api_sports/objects/league.rb
|
53
|
+
- lib/api_sports/objects/lineup.rb
|
54
|
+
- lib/api_sports/objects/odds.rb
|
55
|
+
- lib/api_sports/objects/player.rb
|
56
|
+
- lib/api_sports/objects/prediction.rb
|
57
|
+
- lib/api_sports/objects/season.rb
|
58
|
+
- lib/api_sports/objects/standing.rb
|
59
|
+
- lib/api_sports/objects/statistics.rb
|
60
|
+
- lib/api_sports/objects/team.rb
|
61
|
+
- lib/api_sports/objects/timezone.rb
|
62
|
+
- lib/api_sports/objects/venue.rb
|
63
|
+
- lib/api_sports/resource.rb
|
64
|
+
- lib/api_sports/resources/countries.rb
|
65
|
+
- lib/api_sports/resources/fixtures.rb
|
66
|
+
- lib/api_sports/resources/leagues.rb
|
67
|
+
- lib/api_sports/resources/odds.rb
|
68
|
+
- lib/api_sports/resources/standings.rb
|
69
|
+
- lib/api_sports/resources/teams.rb
|
70
|
+
- lib/api_sports/resources/timezones.rb
|
71
|
+
- lib/api_sports/resources/venues.rb
|
72
|
+
- lib/api_sports/version.rb
|
73
|
+
homepage: https://github.com/irishbryan/api-sports
|
74
|
+
licenses:
|
75
|
+
- MIT
|
76
|
+
metadata:
|
77
|
+
homepage_uri: https://github.com/irishbryan/api-sports
|
78
|
+
source_code_uri: https://github.com/irishbryan/api-sports
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - ">="
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: 2.6.0
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - ">="
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubygems_version: 3.3.26
|
95
|
+
signing_key:
|
96
|
+
specification_version: 4
|
97
|
+
summary: Ruby bindings for the api-sports.io API (Unofficial)
|
98
|
+
test_files: []
|