football-butler 1.0.1 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +4 -4
  2. data/lib/football/butler/api.rb +14 -17
  3. data/lib/football/butler/api_football/base_api_football.rb +17 -0
  4. data/lib/football/butler/api_football/coachs.rb +46 -0
  5. data/lib/football/butler/api_football/countries.rb +39 -0
  6. data/lib/football/butler/api_football/fixtures.rb +80 -0
  7. data/lib/football/butler/api_football/head_to_head.rb +56 -0
  8. data/lib/football/butler/api_football/injuries.rb +62 -0
  9. data/lib/football/butler/api_football/leagues.rb +101 -0
  10. data/lib/football/butler/api_football/lineups.rb +39 -0
  11. data/lib/football/butler/api_football/odds.rb +55 -0
  12. data/lib/football/butler/api_football/players.rb +47 -0
  13. data/lib/football/butler/api_football/predictions.rb +27 -0
  14. data/lib/football/butler/api_football/sidelineds.rb +37 -0
  15. data/lib/football/butler/api_football/standings.rb +35 -0
  16. data/lib/football/butler/api_football/statistics.rb +22 -0
  17. data/lib/football/butler/api_football/teams.rb +66 -0
  18. data/lib/football/butler/api_football/timezones.rb +21 -0
  19. data/lib/football/butler/api_football/top_scorers.rb +22 -0
  20. data/lib/football/butler/api_football/transfers.rb +36 -0
  21. data/lib/football/butler/api_football/trophies.rb +37 -0
  22. data/lib/football/butler/api_football/venues.rb +66 -0
  23. data/lib/football/butler/apifootball/base_apifootball.rb +17 -0
  24. data/lib/football/butler/apifootball/competitions.rb +30 -0
  25. data/lib/football/butler/apifootball/countries.rb +20 -0
  26. data/lib/football/butler/apifootball/events.rb +61 -0
  27. data/lib/football/butler/apifootball/head_to_head.rb +30 -0
  28. data/lib/football/butler/apifootball/lineups.rb +22 -0
  29. data/lib/football/butler/apifootball/odds.rb +25 -0
  30. data/lib/football/butler/apifootball/players.rb +27 -0
  31. data/lib/football/butler/apifootball/predictions.rb +28 -0
  32. data/lib/football/butler/apifootball/standings.rb +23 -0
  33. data/lib/football/butler/apifootball/statistics.rb +22 -0
  34. data/lib/football/butler/apifootball/teams.rb +29 -0
  35. data/lib/football/butler/apifootball/top_scorers.rb +22 -0
  36. data/lib/football/butler/areas.rb +23 -23
  37. data/lib/football/butler/base.rb +45 -18
  38. data/lib/football/butler/coachs.rb +26 -0
  39. data/lib/football/butler/competitions.rb +53 -44
  40. data/lib/football/butler/configuration.rb +275 -14
  41. data/lib/football/butler/countries.rb +11 -0
  42. data/lib/football/butler/events.rb +11 -0
  43. data/lib/football/butler/fixtures.rb +11 -0
  44. data/lib/football/butler/football_data/areas.rb +40 -0
  45. data/lib/football/butler/football_data/competitions.rb +72 -0
  46. data/lib/football/butler/football_data/head_to_head.rb +27 -0
  47. data/lib/football/butler/football_data/lineups.rb +32 -0
  48. data/lib/football/butler/football_data/matches.rb +110 -0
  49. data/lib/football/butler/football_data/odds.rb +27 -0
  50. data/lib/football/butler/football_data/players.rb +20 -0
  51. data/lib/football/butler/football_data/scorers.rb +23 -0
  52. data/lib/football/butler/football_data/standings.rb +47 -0
  53. data/lib/football/butler/football_data/teams.rb +39 -0
  54. data/lib/football/butler/head_to_head.rb +28 -0
  55. data/lib/football/butler/injuries.rb +31 -0
  56. data/lib/football/butler/leagues.rb +11 -0
  57. data/lib/football/butler/lineups.rb +18 -0
  58. data/lib/football/butler/matches.rb +48 -83
  59. data/lib/football/butler/odds.rb +18 -0
  60. data/lib/football/butler/players.rb +26 -0
  61. data/lib/football/butler/predictions.rb +17 -0
  62. data/lib/football/butler/scorers.rb +22 -0
  63. data/lib/football/butler/sidelineds.rb +20 -0
  64. data/lib/football/butler/standings.rb +30 -0
  65. data/lib/football/butler/statistics.rb +17 -0
  66. data/lib/football/butler/teams.rb +23 -23
  67. data/lib/football/butler/tier.rb +26 -11
  68. data/lib/football/butler/timezones.rb +16 -0
  69. data/lib/football/butler/top_scorers.rb +11 -0
  70. data/lib/football/butler/transfers.rb +21 -0
  71. data/lib/football/butler/trophies.rb +21 -0
  72. data/lib/football/butler/venues.rb +34 -0
  73. data/lib/football/butler/version.rb +8 -2
  74. data/lib/football/butler.rb +20 -0
  75. metadata +71 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 664d5c44e79a902f2d22bb75c73ca39dee02907732456193056a614fe673f1e5
4
- data.tar.gz: d4424b42c0e1813b33ec2c1552d331d670d5242e412cb27634c0f9bf7a72ddb7
3
+ metadata.gz: 7654e08d510473c24d9918a1c0c17ad59bf099eaa8ffd7eb2d630e9bf01255e8
4
+ data.tar.gz: 7a921b8c15ea17bf504022db5ea3d5f162cbcaf5665ef0602147cf743f60fd0d
5
5
  SHA512:
6
- metadata.gz: ac787493ada1bf0e49c29adecc0efd254cde6f59d02a4c0ae406898559ca001a6fa5bca5a31705633844c2e509fc928a856c7a2922b0d2465c4500cfe98f5102
7
- data.tar.gz: 99c8a8c61d83d5a8d09ebd973f67d728e6c5fb8c595db8bb1ca0b3dc0658441f9c7fcae64f4d9780128ee6e7418222387f27ee040c2b9ffbfc1b34c68f455d1c
6
+ metadata.gz: a15049ca129fc638e56bb7097a261ac38a87f11f901e481f52115eb89ac6f0cd6047651ef451945317259cfb2f6001647be9b59bee5f6d3197c8d230dc814d8e
7
+ data.tar.gz: d7ecd05456a3a1be9b324a44ec1511d5256e4fba1253efe230715791b0a0f3531e14983a6485f05aa6576c830fc9009e8a25935fa54437ab7d45d33507b5ad53
@@ -30,7 +30,7 @@ module Football
30
30
  end
31
31
 
32
32
  response = process_http_party(path, filters)
33
- Tier.set_from_response_headers(response)
33
+ Configuration.tier_from_response(response)
34
34
 
35
35
  if reached_limit?(response)
36
36
  response = process_retry(path, filters)
@@ -50,7 +50,7 @@ module Football
50
50
  sleep(Tier.get_sleep_seconds) unless Rails.env.test?
51
51
 
52
52
  response = process_http_party(path, filters)
53
- Tier.set_from_response_headers(response)
53
+ Configuration.tier_from_response(response)
54
54
 
55
55
  break unless reached_limit?(response)
56
56
  end
@@ -58,29 +58,23 @@ module Football
58
58
  end
59
59
 
60
60
  def process_http_party(path, filters)
61
- headers = {
62
- "X-Auth-Token": Configuration.api_token
63
- }
64
- url = "#{Configuration.api_endpoint}/#{path}"
65
- query = filters || {}
66
-
61
+ headers = Configuration.http_party_headers
62
+ url = Configuration.http_party_url(path)
63
+ query = filters || {}
67
64
  http_party_get(url, headers, query)
68
65
  end
69
66
 
70
67
  def process_response(response, result)
71
- if response.dig('message')
68
+ if response.parsed_response.is_a?(Hash) && response.dig('message')
72
69
  error_message(response['message'])
73
70
  else
74
- case result
75
- when :default
76
- response
77
- else
78
- response&.keys&.include?(result.to_s) ? response[result.to_s] : nil
79
- end
71
+ Configuration.http_party_response(response, result)
80
72
  end
81
73
  end
82
74
 
83
75
  def http_party_get(url, headers, query)
76
+ Tier.count_request
77
+
84
78
  HTTParty.get "#{url}",
85
79
  headers: headers,
86
80
  query: query,
@@ -88,11 +82,14 @@ module Football
88
82
  end
89
83
 
90
84
  def invalid_config?
91
- Configuration.api_token.blank? || Configuration.api_endpoint.blank?
85
+ Configuration.api_token.blank? || !Configuration.api_name_valid?(Configuration.api_name)
92
86
  end
93
87
 
94
88
  def log(text)
95
- puts "\n\nFootball::Butler::VERSION: #{Football::Butler::VERSION} - #{text}\n\n"
89
+ log_text = "Football::Butler::VERSION: #{Football::Butler::VERSION} - #{text}"
90
+
91
+ puts "\n\n#{log_text}\n\n"
92
+ Football::Butler.logger.debug(log_text)
96
93
  end
97
94
  end
98
95
  end
@@ -0,0 +1,17 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Football
4
+ module Butler
5
+ module ApiFootball
6
+ class BaseApiFootball < Base
7
+
8
+ # class << self
9
+ # def build_path(action)
10
+ # "action=#{action}"
11
+ # end
12
+ # end
13
+
14
+ end
15
+ end
16
+ end
17
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/api_football/base_api_football'
3
+
4
+ module Football
5
+ module Butler
6
+ module ApiFootball
7
+ class Coachs < BaseApiFootball
8
+ PATH = :coachs
9
+
10
+ class << self
11
+ ## COACHS
12
+ #
13
+ # id
14
+ # integer
15
+ # The id of the coach
16
+ #
17
+ # team
18
+ # integer
19
+ # The id of the team
20
+ #
21
+ # search
22
+ # string >= 3 characters
23
+ # The name of the coach
24
+ #
25
+ # /coachs?id={id}
26
+ def by_id(id:, result:, filters:)
27
+ filters.merge!({ id: id })
28
+ Api.get(path: PATH, result: result, filters: filters)
29
+ end
30
+
31
+ # /coachs?search={name}
32
+ def search_by_name(name:, result:, filters:)
33
+ filters.merge!({ search: name })
34
+ Api.get(path: PATH, result: result, filters: filters)
35
+ end
36
+
37
+ # /coachs?team={team}
38
+ def by_team(team:, result:, filters:)
39
+ filters.merge!({ team: team })
40
+ Api.get(path: PATH, result: result, filters: filters)
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/api_football/base_api_football'
3
+
4
+ module Football
5
+ module Butler
6
+ module ApiFootball
7
+ class Countries < BaseApiFootball
8
+ PATH = :countries
9
+
10
+ class << self
11
+ ## COUNTRY
12
+ # /countries?name={name}
13
+ def by_name(name:, result:, filters:)
14
+ filters.merge!({ name: name })
15
+ Api.get(path: PATH, result: result, filters: filters)
16
+ end
17
+
18
+ # /countries?code={code}
19
+ def by_code(code:, result:, filters:)
20
+ filters.merge!({ code: code })
21
+ Api.get(path: PATH, result: result, filters: filters)
22
+ end
23
+
24
+ ## COUNTRIES
25
+ # /countries
26
+ def all(result:)
27
+ Api.get(path: PATH, result: result)
28
+ end
29
+
30
+ # /countries?search={name}
31
+ def search_by_name(name:, result:, filters:)
32
+ filters.merge!({ search: name })
33
+ Api.get(path: PATH, result: result, filters: filters)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -0,0 +1,80 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/api_football/base_api_football'
3
+
4
+ module Football
5
+ module Butler
6
+ module ApiFootball
7
+ class Fixtures < BaseApiFootball
8
+ PATH = :fixtures
9
+
10
+ class << self
11
+ ## FIXTURE
12
+ # /fixtures?id={id}
13
+ def by_id(id:)
14
+ filters = { id: id }
15
+ Api.get(path: PATH, filters: filters, result: :response)
16
+ end
17
+
18
+ ## FIXTURES
19
+ #
20
+ # id
21
+ # integer
22
+ # The id of the fixture
23
+ #
24
+ # live
25
+ # string
26
+ # Enum: "all" "id-id"
27
+ # date
28
+ # stringYYYY-MM-DD
29
+ # A valid date
30
+ #
31
+ # league
32
+ # integer
33
+ # The id of the league
34
+ #
35
+ # season
36
+ # integer 4 characters YYYY
37
+ # The season of the league
38
+ #
39
+ # team
40
+ # integer
41
+ # The id of the team
42
+ #
43
+ # last
44
+ # integer <= 2 characters
45
+ # For the X last fixtures
46
+ #
47
+ # next
48
+ # integer <= 2 characters
49
+ # For the X next fixtures
50
+ #
51
+ # from
52
+ # stringYYYY-MM-DD
53
+ # A valid date
54
+ #
55
+ # to
56
+ # stringYYYY-MM-DD
57
+ # A valid date
58
+ #
59
+ # round
60
+ # string
61
+ # The round of the fixture
62
+ #
63
+ # status
64
+ # string
65
+ # The status short of the fixture
66
+ #
67
+ # timezone
68
+ # string
69
+ # A valid timezone from the endpoint Timezone
70
+ #
71
+ # /fixtures?league={id}&season={year}
72
+ def by_competition_and_year(id:, year:, result:, filters:)
73
+ filters.merge!({ league: id, season: year })
74
+ Api.get(path: PATH, filters: filters, result: result)
75
+ end
76
+ end
77
+ end
78
+ end
79
+ end
80
+ end
@@ -0,0 +1,56 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Football
4
+ module Butler
5
+ module ApiFootball
6
+ class HeadToHead < Base
7
+ PATH = 'fixtures/headtohead'
8
+
9
+ class << self
10
+ ## HEAD TO HEAD
11
+ #
12
+ # h2h
13
+ # required
14
+ # stringID-ID
15
+ # The ids of the teams
16
+ #
17
+ # date
18
+ # stringYYYY-MM-DD
19
+ # league
20
+ # integer
21
+ # The id of the league
22
+ #
23
+ # season
24
+ # integer 4 characters YYYY
25
+ # The season of the league
26
+ #
27
+ # last
28
+ # integer
29
+ # For the X last fixtures
30
+ #
31
+ # next
32
+ # integer
33
+ # For the X next fixtures
34
+ #
35
+ # from
36
+ # stringYYYY-MM-DD
37
+ # to
38
+ # stringYYYY-MM-DD
39
+ # status
40
+ # string
41
+ # The status short of the fixture
42
+ #
43
+ # timezone
44
+ # string
45
+ # A valid timezone from the endpoint Timezone
46
+ #
47
+ # fixtures/headtohead?h2h={team_id-second_team_id}
48
+ def by_teams(team_id:, second_team_id:, filters:, result:)
49
+ filters.merge!(h2h: "#{team_id}-#{second_team_id}")
50
+ Api.get(path: PATH, filters: filters, result: result)
51
+ end
52
+ end
53
+ end
54
+ end
55
+ end
56
+ end
@@ -0,0 +1,62 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/api_football/base_api_football'
3
+
4
+ module Football
5
+ module Butler
6
+ module ApiFootball
7
+ class Injuries < BaseApiFootball
8
+ PATH = :injuries
9
+
10
+ class << self
11
+ ## Injuries
12
+ #
13
+ # league
14
+ # integer
15
+ # The id of the league
16
+ #
17
+ # season
18
+ # integer 4 characters YYYY
19
+ # The season of the league, required with league, team and player parameters
20
+ #
21
+ # fixture
22
+ # integer
23
+ # The id of the fixture
24
+ #
25
+ # team
26
+ # integer
27
+ # The id of the team
28
+ #
29
+ # player
30
+ # integer
31
+ # The id of the player
32
+ #
33
+ # date
34
+ # stringYYYY-MM-DD
35
+ # A valid date
36
+ #
37
+ # timezone
38
+ # string
39
+ # A valid timezone from the endpoint Timezone
40
+ #
41
+ # /injuries?ccompetition={competition}&season={season}
42
+ def by_competition_and_season(competition:, season:, result:, filters:)
43
+ filters.merge!({ league: competition, season: season })
44
+ Api.get(path: PATH, result: result, filters: filters)
45
+ end
46
+
47
+ # /injuries?fixture={match}
48
+ def by_match(match:, result:, filters:)
49
+ filters.merge!({ fixture: match })
50
+ Api.get(path: PATH, result: result, filters: filters)
51
+ end
52
+
53
+ # /injuries?team={team}&season={season}
54
+ def by_team_and_season(team:, season:, result:, filters:)
55
+ filters.merge!({ team: team, season: season })
56
+ Api.get(path: PATH, result: result, filters: filters)
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
62
+ end
@@ -0,0 +1,101 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/api_football/base_api_football'
3
+
4
+ module Football
5
+ module Butler
6
+ module ApiFootball
7
+ class Leagues < BaseApiFootball
8
+ PATH = :leagues
9
+
10
+ class << self
11
+ ## LEAGUE
12
+ # /leagues?id={id}
13
+ def by_id(id:)
14
+ filters = { id: id }
15
+ Api.get(path: PATH, filters: filters, result: :response)
16
+ end
17
+
18
+ # /leagues?country={country}
19
+ def by_country_name(name:, result:)
20
+ filters = { country: name }
21
+ Api.get(path: PATH, filters: filters, result: result)
22
+ end
23
+
24
+ # /leagues/seasons
25
+ def all_seasons(result:)
26
+ path = "#{PATH}/seasons"
27
+ Api.get(path: path, result: result)
28
+ end
29
+
30
+ ## LEAGUES
31
+ # https://www.api-football.com/documentation-v3#operation/get-leagues
32
+ #
33
+ # id
34
+ # integer
35
+ # The id of the league
36
+ #
37
+ # name
38
+ # string
39
+ # The name of the league
40
+ #
41
+ # country
42
+ # string
43
+ # The country name of the league
44
+ #
45
+ # code
46
+ # string 2 characters FR, GB, IT…
47
+ # The Alpha2 code of the country
48
+ #
49
+ # season
50
+ # integer 4 characters YYYY
51
+ # The season of the league
52
+ #
53
+ # team
54
+ # integer
55
+ # The id of the team
56
+ #
57
+ # type
58
+ # string
59
+ # Enum: "league" "cup"
60
+ # The type of the league
61
+ #
62
+ # current
63
+ # string
64
+ # Enum: "true" "false"
65
+ # The state of the league
66
+ #
67
+ # search
68
+ # string >= 3 characters
69
+ # The name or the country of the league
70
+ #
71
+ # last
72
+ # integer <= 2 characters
73
+ #
74
+ # /leagues
75
+ def all(result:, filters:)
76
+ Api.get(path: PATH, result: result, filters: filters)
77
+ end
78
+
79
+ # /leagues?search={name}
80
+ def search_by_name(name:, filters:, result:)
81
+ filters.merge!({ search: name })
82
+ Api.get(path: PATH, filters: filters, result: result)
83
+ end
84
+
85
+ # /leagues?type=league
86
+ def all_leagues(result:, filters:)
87
+ filters.merge!({ type: 'league' })
88
+ Api.get(path: PATH, result: result, filters: filters)
89
+ end
90
+
91
+ # /leagues?type=cup
92
+ def all_cups(result:, filters:)
93
+ filters.merge!({ type: 'cup' })
94
+ Api.get(path: PATH, result: result, filters: filters)
95
+ end
96
+ end
97
+
98
+ end
99
+ end
100
+ end
101
+ end