api_football_v3 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8f766b7f4ba6d62e858803d54a906759715c02ace7f365d9f7da96d1c7b59094
4
+ data.tar.gz: 38cd3dc31c18d72fb9e433c269bb9068f495dc2279325fc6648315a107619b34
5
+ SHA512:
6
+ metadata.gz: bca6e2c4a3ac9f8f8af0a22a608cbc213c6335e2d2ba2ce788e65a396bdfb7df5c058a00ecba437716c17c306cd720d0011d0da5ec7566eff7f2078c6db21070
7
+ data.tar.gz: f5726d1272786dfc1341e0e74418b074076d8742a278dcfee8eb195bddc7231fd612b4071d04721283d1192ebeacddecfc340eb8048a69d39fe64ce67424d54b
data/LICENSE.md ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2020 Agustin Gomez Campero
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,242 @@
1
+ # The Football API Ruby Gem
2
+
3
+ A Ruby interface to [API Football v3](https://www.api-football.com)
4
+
5
+ This gem won't work with v1 or v2 of the API
6
+
7
+ ## Installation
8
+ Add this line to your application's Gemfile:
9
+
10
+ ```ruby
11
+ gem 'api_football_v3'
12
+ ```
13
+
14
+ And then execute:
15
+
16
+ $ bundle
17
+
18
+ Or install it yourself as:
19
+
20
+ $ gem install api_football_v3
21
+
22
+ ## Configurations
23
+ Configure `api_football_v3` with your API-Key and the URL (depends on whether you are subscribed via RapidApi or ApiSports)
24
+
25
+ ```ruby
26
+ @client = ApiFootballV3::Client.new do |config|
27
+ config.api_key = "YOUR_API_KEY"
28
+ config.base_url = "https://api-football-beta.p.rapidapi.com/" # or https://v3.football.api-sports.io/
29
+ end
30
+ ```
31
+
32
+ ## Usage
33
+ Endpoints can be accessed using built in functions that take options as a parameter.
34
+ In all cases options is a hash and they return a JSON object.
35
+
36
+ Examples:
37
+ ```ruby
38
+ @client.countries(search: "Chile")
39
+ ```
40
+ Response:
41
+ ```
42
+ {
43
+ "get": "countries",
44
+ "parameters": {
45
+ "search": "Chile"
46
+ },
47
+ "errors": [],
48
+ "results": 1,
49
+ "paging": {
50
+ "current": 1,
51
+ "total": 1
52
+ },
53
+ "response": [
54
+ {
55
+ "name": "Chile",
56
+ "code": "CL",
57
+ "flag": "https://media.api-sports.io/flags/cl.svg"
58
+ }
59
+ ]
60
+ }
61
+ ```
62
+
63
+ ```ruby
64
+ @client.leagues(country: "Chile", season: 2020)
65
+ ```
66
+ Response:
67
+ ```
68
+ {
69
+ "get": "leagues",
70
+ "parameters": {
71
+ "country": "Chile",
72
+ "season": "2020"
73
+ },
74
+ "errors": [],
75
+ "results": 2,
76
+ "paging": {
77
+ "current": 1,
78
+ "total": 1
79
+ },
80
+ "response": [
81
+ {
82
+ "league": {
83
+ "id": 265,
84
+ "name": "Primera Division",
85
+ "type": "League",
86
+ "logo": "https://media.api-sports.io/football/leagues/265.png"
87
+ },
88
+ "country": {
89
+ "name": "Chile",
90
+ "code": "CL",
91
+ "flag": "https://media.api-sports.io/flags/cl.svg"
92
+ },
93
+ "seasons": [
94
+ {
95
+ "year": 2020,
96
+ "start": "2020-01-24",
97
+ "end": "2020-10-11",
98
+ "current": true,
99
+ "coverage": {
100
+ "fixtures": {
101
+ "events": true,
102
+ "lineups": true,
103
+ "statistics_fixtures": true,
104
+ "statistics_players": true
105
+ },
106
+ "standings": true,
107
+ "players": true,
108
+ "top_scorers": true,
109
+ "predictions": true,
110
+ "odds": true
111
+ }
112
+ }
113
+ ]
114
+ },
115
+ {
116
+ "league": {
117
+ "id": 266,
118
+ "name": "Primera B",
119
+ "type": "League",
120
+ "logo": "https://media.api-sports.io/football/leagues/266.png"
121
+ },
122
+ "country": {
123
+ "name": "Chile",
124
+ "code": "CL",
125
+ "flag": "https://media.api-sports.io/flags/cl.svg"
126
+ },
127
+ "seasons": [
128
+ {
129
+ "year": 2020,
130
+ "start": "2020-02-22",
131
+ "end": "2020-10-05",
132
+ "current": true,
133
+ "coverage": {
134
+ "fixtures": {
135
+ "events": true,
136
+ "lineups": true,
137
+ "statistics_fixtures": false,
138
+ "statistics_players": false
139
+ },
140
+ "standings": true,
141
+ "players": true,
142
+ "top_scorers": true,
143
+ "predictions": true,
144
+ "odds": true
145
+ }
146
+ }
147
+ ]
148
+ }
149
+ ]
150
+ }
151
+ ```
152
+
153
+ Here you can see how you can call all available endpoints.
154
+ For information on options on each endpoint please review the [official documentation](https://www.api-football.com/documentation-beta).
155
+
156
+
157
+ ```ruby
158
+ @client.coaches # /coachs
159
+
160
+ @client.countries # /countries
161
+
162
+ @client.fixtures # /fixtures
163
+ @client.live # /fixtures?live=all
164
+ @client.rounds # /fixtures/rounds
165
+ @client.head_to_head # /fixtures/headtohead
166
+ @client.fixture_statistics # /fixtures/statistics
167
+ @client.fixture_events # /fixtures/events
168
+ @client.fixture_lineups # /fixtures/lineups
169
+ @client.fixture_player_statistics # /fixtures/players
170
+
171
+ @client.leagues # /leagues
172
+ @client.leagues_seasons # /leagues/seasons
173
+
174
+ @client.odds # /odds
175
+ @client.mapping # /odds/mapping
176
+ @client.bookmakers # /odds/bookmakers
177
+ @client.bets # /odds/bets
178
+
179
+ @client.players # /players
180
+ @client.top_scorers # /players/topscorers
181
+ @client.players_seasons # /players/seasons
182
+
183
+ @client.predictions # /predictions
184
+
185
+ @client.sidelined # /sidelined
186
+
187
+ @client.standings # /standings
188
+
189
+ @client.teams # /teams
190
+ @client.team_statistics # /teams/statistics
191
+
192
+ @client.timezones # /timezone
193
+
194
+ @client.transfers # /transfers
195
+
196
+ @client.trophies # /trophies
197
+
198
+ @client.venues # /venues
199
+ ```
200
+
201
+ All endpoints can also be accessed using `get(endpoint, options)`.
202
+
203
+ Example:
204
+ ```ruby
205
+ @client.get('/teams', { id: 2323 })
206
+ ```
207
+ Response:
208
+ ```
209
+ {
210
+ "get":"teams",
211
+ "parameters":{
212
+ "id":"2323"
213
+ },
214
+ "errors":[],
215
+ "results":1,
216
+ "paging":{
217
+ "current":1,
218
+ "total":1
219
+ },
220
+ "response":[
221
+ {
222
+ "team":{
223
+ "id":2323,
224
+ "name":"Universidad de Chile",
225
+ "country":"Chile",
226
+ "founded":1927,
227
+ "national":false,
228
+ "logo":"https://media.api-sports.io/football/teams/2323.png"
229
+ },
230
+ "venue":{
231
+ "id":316,
232
+ "name":"Estadio Nacional Julio Mart\u00EDnez Pr\u00E1danos",
233
+ "address":"Avenida Grecia 2001, \u00D1u\u00F1oa",
234
+ "city":"Santiago de Chile",
235
+ "capacity":48665,
236
+ "surface":"grass",
237
+ "image":"https://media.api-sports.io/football/venues/316.png"
238
+ }
239
+ }
240
+ ]
241
+ }
242
+ ```
@@ -0,0 +1,12 @@
1
+ Gem::Specification.new do |spec|
2
+ spec.name = "api_football_v3"
3
+ spec.version = "0.0.2"
4
+ spec.authors = ["agomezcampero"]
5
+ spec.email = ["agomezcampero@gmail.com"]
6
+ spec.date = "2020-09-17"
7
+ spec.summary = "A gem to connect to api-football v3, www.api-football.com"
8
+ spec.files = %w[LICENSE.md README.md api_football_v3.gemspec] + Dir['lib/**/*.rb']
9
+ spec.homepage = 'https://github.com/agomezcampero/api_football_v3'
10
+ spec.require_paths = ["lib"]
11
+ spec.licenses = %w[MIT]
12
+ end
@@ -0,0 +1 @@
1
+ require 'api_football_v3/client'
@@ -0,0 +1,17 @@
1
+ require 'api_football_v3/rest/api'
2
+ require 'api_football_v3/request'
3
+
4
+ module ApiFootballV3
5
+ class Client
6
+ include ApiFootballV3::Rest::Api
7
+ include ApiFootballV3::Request
8
+ attr_accessor :api_key, :base_url
9
+
10
+ def initialize(options = {})
11
+ options.each do |key, value|
12
+ instance_variable_set("@#{key}", value)
13
+ end
14
+ yield(self) if block_given?
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,36 @@
1
+ module ApiFootballV3
2
+ class Error < StandardError
3
+ attr_reader :code
4
+
5
+ ClientError = Class.new(self)
6
+ BadRequest = Class.new(ClientError)
7
+ Unauthorized = Class.new(ClientError)
8
+ Forbidden = Class.new(ClientError)
9
+ NotFound = Class.new(ClientError)
10
+ NotAcceptable = Class.new(ClientError)
11
+ RequestEntityTooLarge = Class.new(ClientError)
12
+ UnprocessableEntity = Class.new(ClientError)
13
+ TooManyRequests = Class.new(ClientError)
14
+
15
+ ServerError = Class.new(self)
16
+ InternalServerError = Class.new(ServerError)
17
+ BadGateway = Class.new(ServerError)
18
+ ServiceUnavailable = Class.new(ServerError)
19
+ GatewayTimeout = Class.new(ServerError)
20
+
21
+ ERRORS = {
22
+ 400 => ApiFootballV3::Error::BadRequest,
23
+ 401 => ApiFootballV3::Error::Unauthorized,
24
+ 403 => ApiFootballV3::Error::Forbidden,
25
+ 404 => ApiFootballV3::Error::NotFound,
26
+ 406 => ApiFootballV3::Error::NotAcceptable,
27
+ 413 => ApiFootballV3::Error::RequestEntityTooLarge,
28
+ 422 => ApiFootballV3::Error::UnprocessableEntity,
29
+ 429 => ApiFootballV3::Error::TooManyRequests,
30
+ 500 => ApiFootballV3::Error::InternalServerError,
31
+ 502 => ApiFootballV3::Error::BadGateway,
32
+ 503 => ApiFootballV3::Error::ServiceUnavailable,
33
+ 504 => ApiFootballV3::Error::GatewayTimeout
34
+ }.freeze
35
+ end
36
+ end
@@ -0,0 +1,51 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'openssl'
4
+ require 'json'
5
+ require 'api_football_v3/error'
6
+
7
+ module ApiFootballV3
8
+ module Request
9
+ def get(path, options = {})
10
+ @path = path
11
+ @options = options
12
+ perform_get_request
13
+ end
14
+
15
+ private
16
+
17
+ def perform_get_request
18
+ response = http.request(request)
19
+ response_body = response.read_body ? JSON.parse(response.read_body) : ''
20
+ raise(error(response.code), response_body) unless response.is_a?(Net::HTTPSuccess)
21
+
22
+ response_body
23
+ end
24
+
25
+ def url
26
+ URI(@base_url + @path + query_params)
27
+ end
28
+
29
+ def query_params
30
+ '?' + URI.encode_www_form(@options)
31
+ end
32
+
33
+ def http
34
+ http = Net::HTTP.new(url.host, url.port)
35
+ http.use_ssl = true
36
+ http.verify_mode = OpenSSL::SSL::VERIFY_NONE
37
+ http
38
+ end
39
+
40
+ def request
41
+ request = Net::HTTP::Get.new(url)
42
+ request["x-rapidapi-key"] = @api_key
43
+ request
44
+ end
45
+
46
+ def error(code)
47
+ klass = ApiFootballV3::Error::ERRORS[code.to_i]
48
+ klass || ApiFootballV3::Error
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,35 @@
1
+ require 'api_football_v3/rest/coaches'
2
+ require 'api_football_v3/rest/countries'
3
+ require 'api_football_v3/rest/fixtures'
4
+ require 'api_football_v3/rest/leagues'
5
+ require 'api_football_v3/rest/odds'
6
+ require 'api_football_v3/rest/players'
7
+ require 'api_football_v3/rest/predictions'
8
+ require 'api_football_v3/rest/sidelined'
9
+ require 'api_football_v3/rest/standings'
10
+ require 'api_football_v3/rest/teams'
11
+ require 'api_football_v3/rest/timezones'
12
+ require 'api_football_v3/rest/transfers'
13
+ require 'api_football_v3/rest/trophies'
14
+ require 'api_football_v3/rest/venues'
15
+
16
+ module ApiFootballV3
17
+ module Rest
18
+ module Api
19
+ include ApiFootballV3::Rest::Coaches
20
+ include ApiFootballV3::Rest::Countries
21
+ include ApiFootballV3::Rest::Fixtures
22
+ include ApiFootballV3::Rest::Leagues
23
+ include ApiFootballV3::Rest::Odds
24
+ include ApiFootballV3::Rest::Players
25
+ include ApiFootballV3::Rest::Predictions
26
+ include ApiFootballV3::Rest::Sidelined
27
+ include ApiFootballV3::Rest::Standings
28
+ include ApiFootballV3::Rest::Teams
29
+ include ApiFootballV3::Rest::Timezones
30
+ include ApiFootballV3::Rest::Transfers
31
+ include ApiFootballV3::Rest::Trophies
32
+ include ApiFootballV3::Rest::Venues
33
+ end
34
+ end
35
+ end
@@ -0,0 +1,9 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Coaches
4
+ def coaches(options = {})
5
+ get('/coachs', options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Countries
4
+ def countries(options = {})
5
+ get('/countries', options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,37 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Fixtures
4
+ def fixtures(options = {})
5
+ get('/fixtures', options)
6
+ end
7
+
8
+ def live
9
+ get('/fixtures', { live: 'all' })
10
+ end
11
+
12
+ def rounds(options = {})
13
+ get('/fixtures/rounds', options)
14
+ end
15
+
16
+ def head_to_head(options = {})
17
+ get('/fixtures/headtohead', options)
18
+ end
19
+
20
+ def fixture_statistics(options = {})
21
+ get('/fixtures/statistics', options)
22
+ end
23
+
24
+ def fixture_events(options = {})
25
+ get('/fixtures/events', options)
26
+ end
27
+
28
+ def fixture_lineups(options = {})
29
+ get('/fixtures/lineups', options)
30
+ end
31
+
32
+ def fixture_player_statistics(options = {})
33
+ get('/fixtures/players', options)
34
+ end
35
+ end
36
+ end
37
+ end
@@ -0,0 +1,13 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Leagues
4
+ def leagues(options = {})
5
+ get('/leagues', options)
6
+ end
7
+
8
+ def leagues_seasons
9
+ get('/leagues/seasons')
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,21 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Odds
4
+ def odds(options = {})
5
+ get('/odds', options)
6
+ end
7
+
8
+ def mapping(options = {})
9
+ get('/odds/mapping', options)
10
+ end
11
+
12
+ def bookmakers(options = {})
13
+ get('/odds/bookmakers', options)
14
+ end
15
+
16
+ def bets(options = {})
17
+ get('/odds/bets', options)
18
+ end
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,17 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Players
4
+ def players(options = {})
5
+ get('/players', options)
6
+ end
7
+
8
+ def top_scorers(options = {})
9
+ get('/players/topscorers', options)
10
+ end
11
+
12
+ def players_seasons
13
+ get('/players/seasons')
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,9 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Predictions
4
+ def predictions(options = {})
5
+ get('/predictions', options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Sidelined
4
+ def sidelined(options = {})
5
+ get('/sidelined', options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Standings
4
+ def standings(options = {})
5
+ get('/standings', options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,13 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Teams
4
+ def teams(options = {})
5
+ get('/teams', options)
6
+ end
7
+
8
+ def team_statistics(options = {})
9
+ get('/teams/statistics', options)
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,9 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Timezones
4
+ def timezones
5
+ get('/timezone')
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Transfers
4
+ def transfers(options = {})
5
+ get('/transfers', options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Trophies
4
+ def trophies(options = {})
5
+ get('/trophies', options)
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module ApiFootballV3
2
+ module Rest
3
+ module Venues
4
+ def venues(options = {})
5
+ get('/venues', options)
6
+ end
7
+ end
8
+ end
9
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: api_football_v3
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ platform: ruby
6
+ authors:
7
+ - agomezcampero
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2020-09-17 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ - agomezcampero@gmail.com
16
+ executables: []
17
+ extensions: []
18
+ extra_rdoc_files: []
19
+ files:
20
+ - LICENSE.md
21
+ - README.md
22
+ - api_football_v3.gemspec
23
+ - lib/api_football_v3.rb
24
+ - lib/api_football_v3/client.rb
25
+ - lib/api_football_v3/error.rb
26
+ - lib/api_football_v3/request.rb
27
+ - lib/api_football_v3/rest/api.rb
28
+ - lib/api_football_v3/rest/coaches.rb
29
+ - lib/api_football_v3/rest/countries.rb
30
+ - lib/api_football_v3/rest/fixtures.rb
31
+ - lib/api_football_v3/rest/leagues.rb
32
+ - lib/api_football_v3/rest/odds.rb
33
+ - lib/api_football_v3/rest/players.rb
34
+ - lib/api_football_v3/rest/predictions.rb
35
+ - lib/api_football_v3/rest/sidelined.rb
36
+ - lib/api_football_v3/rest/standings.rb
37
+ - lib/api_football_v3/rest/teams.rb
38
+ - lib/api_football_v3/rest/timezones.rb
39
+ - lib/api_football_v3/rest/transfers.rb
40
+ - lib/api_football_v3/rest/trophies.rb
41
+ - lib/api_football_v3/rest/venues.rb
42
+ homepage: https://github.com/agomezcampero/api_football_v3
43
+ licenses:
44
+ - MIT
45
+ metadata: {}
46
+ post_install_message:
47
+ rdoc_options: []
48
+ require_paths:
49
+ - lib
50
+ required_ruby_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ version: '0'
55
+ required_rubygems_version: !ruby/object:Gem::Requirement
56
+ requirements:
57
+ - - ">="
58
+ - !ruby/object:Gem::Version
59
+ version: '0'
60
+ requirements: []
61
+ rubygems_version: 3.1.2
62
+ signing_key:
63
+ specification_version: 4
64
+ summary: A gem to connect to api-football v3, www.api-football.com
65
+ test_files: []