football-butler 1.1.1 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/lib/football/butler.rb +10 -0
  3. data/lib/football/butler/api.rb +8 -16
  4. data/lib/football/butler/apifootball/base_apifootball.rb +17 -0
  5. data/lib/football/butler/apifootball/competitions.rb +30 -0
  6. data/lib/football/butler/apifootball/countries.rb +20 -0
  7. data/lib/football/butler/apifootball/events.rb +61 -0
  8. data/lib/football/butler/apifootball/head_to_head.rb +30 -0
  9. data/lib/football/butler/apifootball/lineups.rb +22 -0
  10. data/lib/football/butler/apifootball/odds.rb +25 -0
  11. data/lib/football/butler/apifootball/players.rb +27 -0
  12. data/lib/football/butler/apifootball/predictions.rb +28 -0
  13. data/lib/football/butler/apifootball/standings.rb +23 -0
  14. data/lib/football/butler/apifootball/statistics.rb +22 -0
  15. data/lib/football/butler/apifootball/teams.rb +29 -0
  16. data/lib/football/butler/apifootball/top_scorers.rb +22 -0
  17. data/lib/football/butler/areas.rb +15 -24
  18. data/lib/football/butler/base.rb +47 -17
  19. data/lib/football/butler/competitions.rb +31 -44
  20. data/lib/football/butler/configuration.rb +166 -11
  21. data/lib/football/butler/countries.rb +10 -0
  22. data/lib/football/butler/events.rb +10 -0
  23. data/lib/football/butler/football_data/areas.rb +40 -0
  24. data/lib/football/butler/football_data/competitions.rb +72 -0
  25. data/lib/football/butler/football_data/head_to_head.rb +27 -0
  26. data/lib/football/butler/football_data/lineups.rb +32 -0
  27. data/lib/football/butler/football_data/matches.rb +110 -0
  28. data/lib/football/butler/football_data/odds.rb +27 -0
  29. data/lib/football/butler/football_data/players.rb +20 -0
  30. data/lib/football/butler/football_data/scorers.rb +23 -0
  31. data/lib/football/butler/football_data/standings.rb +47 -0
  32. data/lib/football/butler/football_data/teams.rb +39 -0
  33. data/lib/football/butler/head_to_head.rb +27 -0
  34. data/lib/football/butler/lineups.rb +17 -0
  35. data/lib/football/butler/matches.rb +47 -83
  36. data/lib/football/butler/odds.rb +17 -0
  37. data/lib/football/butler/players.rb +21 -0
  38. data/lib/football/butler/predictions.rb +16 -0
  39. data/lib/football/butler/scorers.rb +17 -0
  40. data/lib/football/butler/standings.rb +15 -29
  41. data/lib/football/butler/statistics.rb +16 -0
  42. data/lib/football/butler/teams.rb +14 -23
  43. data/lib/football/butler/top_scorers.rb +10 -0
  44. data/lib/football/butler/version.rb +5 -2
  45. metadata +40 -7
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: da1a761c34181fe29d026b0c67c603b188778cc3c7e96dfc9b9b66ab159bd7f4
4
- data.tar.gz: d419e72dbc8783b1352cf8bc60b3d1031b82d62bc94f086516fdda6e54c38ba4
3
+ metadata.gz: 1c077c75793e868d1fd0365e45a510c3b97c5d1f0f859f80887eba0bade07811
4
+ data.tar.gz: 481518df0c7b9bd0d2f7abe55f2d3aa513a55b8818731cd862a2573409e94e03
5
5
  SHA512:
6
- metadata.gz: 1adebe7bf672347d8580583fc1679a459a08c2c1e89df49737b38758126525ac83cf80e3b6d516df9d3ce6860f2ae6207d25736e1cf701ba3b85595e187eb586
7
- data.tar.gz: 9fbf029e5569667d842469cc16795b6c0b2a2de9260045c9f75f0c774bd13b5898f3119af1696e793c30024e40ffaf5f1c748f7705201781db0c8d2b062a34a8
6
+ metadata.gz: b7cabe54a4364c5f540da14aa7c7b54f23a7d0067e9626ba1446a657acff2ad4ab4bc9c10b520321d05f7ae83d08ce7a7a32bc9b2e37f940826c9b699114dc51
7
+ data.tar.gz: 9eaae81bf0c1691d2142349c3be200a6b28128e77c0402791820d3761f04f31ccb7dba4e6bc3a61ff95072c5e202f0ab771b02103cb71fdd04ef53690f073551
@@ -10,6 +10,16 @@ require 'football/butler/matches'
10
10
  require 'football/butler/areas'
11
11
  require 'football/butler/teams'
12
12
  require 'football/butler/standings'
13
+ require 'football/butler/countries'
14
+ require 'football/butler/events'
15
+ require 'football/butler/players'
16
+ require 'football/butler/scorers'
17
+ require 'football/butler/top_scorers'
18
+ require 'football/butler/lineups'
19
+ require 'football/butler/statistics'
20
+ require 'football/butler/odds'
21
+ require 'football/butler/head_to_head'
22
+ require 'football/butler/predictions'
13
23
 
14
24
  module Football
15
25
  module Butler
@@ -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,25 +58,17 @@ 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
 
@@ -88,7 +80,7 @@ module Football
88
80
  end
89
81
 
90
82
  def invalid_config?
91
- Configuration.api_token.blank? || Configuration.api_endpoint.blank?
83
+ Configuration.api_token.blank? || !Configuration.api_name_valid?(Configuration.api_name)
92
84
  end
93
85
 
94
86
  def log(text)
@@ -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,30 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/base_apifootball'
3
+
4
+ module Football
5
+ module Butler
6
+ module Apifootball
7
+ class Competitions < BaseApifootball
8
+ PATH = :get_leagues
9
+
10
+ class << self
11
+ ## COMPETITION
12
+ # action=get_leagues&country_id={id}
13
+ def by_country(id:)
14
+ filters = { country_id: id }
15
+ Api.get(path: build_path(PATH), filters: filters)
16
+ end
17
+
18
+ ## COMPETITIONS
19
+ #
20
+ # country_id Country ID - if set only leagues from specific country will be returned (Optional)
21
+ #
22
+ # action=get_league
23
+ def all(result:, filters:)
24
+ Api.get(path: build_path(PATH), result: result, filters: filters)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/base_apifootball'
3
+
4
+ module Football
5
+ module Butler
6
+ module Apifootball
7
+ class Countries < BaseApifootball
8
+ PATH = :get_countries
9
+
10
+ class << self
11
+ ## COUNTRIES
12
+ # action=get_leagues
13
+ def all(result:)
14
+ Api.get(path: build_path(PATH), result: result)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,61 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/base_apifootball'
3
+
4
+ module Football
5
+ module Butler
6
+ module Apifootball
7
+ class Events < BaseApifootball
8
+ PATH = :get_events
9
+
10
+ class << self
11
+ ## EVENT
12
+ # action=get_events?match_id={id}
13
+ def by_id(id:)
14
+ filters = { match_id: id }
15
+ Api.get(path: build_path(PATH), result: :parsed_response, filters: filters)
16
+ end
17
+
18
+ ## EVENTS
19
+ #
20
+ # timezone Default timezone: Europe/Berlin.
21
+ # With this filter you can set the timezone where you want to receive the data.
22
+ # Timezone is in TZ format (exemple: America/New_York). (Optional)
23
+ # from Start date (yyyy-mm-dd)
24
+ # to Stop date (yyyy-mm-dd)
25
+ # country_id Country ID if set only leagues from specific country will be returned (Optional)
26
+ # league_id League ID if set events from specific league will be returned (Optional)
27
+ # match_id Match ID if set only details from specific match will be returned (Optional)
28
+ # team_id Team ID if set only details from specific team will be returned (Optional)
29
+ #
30
+ # action=get_events&...<AT LEAST ONE PARAMETER IS REQUIRED!>
31
+ # "error": 201, "message": "Required parameters missing"
32
+ def all(result:, filters:)
33
+ Api.get(path: build_path(PATH), result: result, filters: filters)
34
+ end
35
+
36
+ ## by COMPETITION
37
+ # action=get_events?league_id={id}
38
+ def by_competition(id:, result:, filters:)
39
+ filters.merge!({ league_id: id })
40
+ Api.get(path: build_path(PATH), filters: filters, result: result)
41
+ end
42
+
43
+ # action=get_events?league_id={id}&from={year}-01-01&{year}-12-31
44
+ def by_competition_and_year(id:, year:, result:, filters:)
45
+ from = "#{year}-01-01"
46
+ to = "#{year}-12-31"
47
+ filters.merge!({ league_id: id, from: from, to: to })
48
+ Api.get(path: build_path(PATH), filters: filters, result: result)
49
+ end
50
+
51
+ ## by TEAM
52
+ # action=get_events?team_id={id}
53
+ def by_team(id:, result:, filters:)
54
+ filters.merge!({ team_id: id })
55
+ Api.get(path: build_path(PATH), result: result, filters: filters)
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
61
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/base_apifootball'
3
+
4
+ module Football
5
+ module Butler
6
+ module Apifootball
7
+ class HeadToHead < BaseApifootball
8
+ PATH = :get_H2H
9
+
10
+ class << self
11
+ ## HEAD TO HEAD
12
+ #
13
+ # timezone Default timezone: Europe/Berlin. With this filter you can set the timezone
14
+ # where you want to receive the data. Timezone is in TZ format (exemple: America/New_York).
15
+ # (Optional)
16
+ # firstTeam First team name
17
+ # secondTeam Second team name
18
+ # firstTeamId First team Id
19
+ # secondTeamId Second team Id
20
+ #
21
+ # action=get_H2H&firstTeamId={team_id}&secondTeamId={second_team_id}
22
+ def by_teams(team_id:, second_team_id:, filters:, result:)
23
+ filters.merge!(firstTeamId: team_id, secondTeamId: second_team_id)
24
+ Api.get(path: build_path(PATH), filters: filters, result: result)
25
+ end
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/base_apifootball'
3
+
4
+ module Football
5
+ module Butler
6
+ module Apifootball
7
+ class Lineups < BaseApifootball
8
+ PATH = :get_lineups
9
+
10
+ class << self
11
+ ## LINEUPS
12
+ #
13
+ # action=get_lineups&match_id={id}
14
+ def by_match(id:)
15
+ filters = { match_id: id }
16
+ Api.get(path: build_path(PATH), filters: filters, result: :parsed_response)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/base_apifootball'
3
+
4
+ module Football
5
+ module Butler
6
+ module Apifootball
7
+ class Odds < BaseApifootball
8
+ PATH = :get_odds
9
+
10
+ class << self
11
+ ## ODDS
12
+ #
13
+ # from Start date (yyyy-mm-dd)
14
+ # to Stop date (yyyy-mm-dd)
15
+ #
16
+ # action=get_odds&match_id={id}&from={from}&to={to}
17
+ def by_match(id:, from:, to:)
18
+ filters = { match_id: id, from: from, to: to }
19
+ Api.get(path: build_path(PATH), filters: filters, result: :parsed_response)
20
+ end
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/base_apifootball'
3
+
4
+ module Football
5
+ module Butler
6
+ module Apifootball
7
+ class Players < BaseApifootball
8
+ PATH = :get_players
9
+
10
+ class << self
11
+ ## PLAYER
12
+ # action=get_players?player_id={id}
13
+ def by_id(id:)
14
+ filters = { player_id: id }
15
+ Api.get(path: build_path(PATH), filters: filters, result: :parsed_response)
16
+ end
17
+
18
+ # action=get_players?name={name}
19
+ def by_name(name:, result:)
20
+ filters = { player_name: name }
21
+ Api.get(path: build_path(PATH), filters: filters, result: result)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,28 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/base_apifootball'
3
+
4
+ module Football
5
+ module Butler
6
+ module Apifootball
7
+ class Predictions < BaseApifootball
8
+ PATH = :get_predictions
9
+
10
+ class << self
11
+ ## PREDICTIONS
12
+ #
13
+ # from Start date (yyyy-mm-dd)
14
+ # to Stop date (yyyy-mm-dd)
15
+ # country_id Country ID - if set only leagues from specific country will be returned (Optional)
16
+ # league_id League ID - if set events from specific league will be returned (Optional)
17
+ # match_id Match ID - if set only details from specific match will be returned (Optional)
18
+ #
19
+ # get_predictions&match_id={id}
20
+ def by_match(id:, filters:, result:)
21
+ filters.merge!(match_id: id)
22
+ Api.get(path: build_path(PATH), filters: filters, result: result)
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
28
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/base_apifootball'
3
+
4
+ module Football
5
+ module Butler
6
+ module Apifootball
7
+ class Standings < BaseApifootball
8
+ PATH = :get_standings
9
+
10
+ class << self
11
+ ## STANDINGS / League
12
+ #
13
+ # action=get_standings&league_id={id}
14
+ def by_competition(id:, result: , filters:)
15
+ filters.merge!({ league_id: id })
16
+ Api.get(path: build_path(PATH), result: result, filters: filters)
17
+ end
18
+ end
19
+
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/base_apifootball'
3
+
4
+ module Football
5
+ module Butler
6
+ module Apifootball
7
+ class Statistics < BaseApifootball
8
+ PATH = :get_statistics
9
+
10
+ class << self
11
+ ## STATISTICS
12
+ #
13
+ # action=get_statistics&match_id={id}
14
+ def by_match(id:, result:)
15
+ filters = { match_id: id }
16
+ Api.get(path: build_path(PATH), filters: filters, result: result)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/base_apifootball'
3
+
4
+ module Football
5
+ module Butler
6
+ module Apifootball
7
+ class Teams < BaseApifootball
8
+ PATH = :get_teams
9
+
10
+ class << self
11
+ ## TEAM
12
+ # action=get_teams&team_id={id}
13
+ def by_id(id:)
14
+ filters = { team_id: id }
15
+ Api.get(path: build_path(PATH), filters: filters, result: :parsed_response)
16
+ end
17
+
18
+ ## COMPETITION
19
+ # action=get_teams&league_id={id}
20
+ def by_competition(id:, result:, filters:)
21
+ filters.merge!({ league_id: id })
22
+ Api.get(path: build_path(PATH), result: result, filters: filters)
23
+ end
24
+ end
25
+
26
+ end
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,22 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/base_apifootball'
3
+
4
+ module Football
5
+ module Butler
6
+ module Apifootball
7
+ class TopScorers < BaseApifootball
8
+ PATH = :get_topscorers
9
+
10
+ class << self
11
+ ## TOP SCORER
12
+ #
13
+ # action=get_topscorers?league_id={id}
14
+ def by_competition(id:, result:, filters:)
15
+ filters.merge!({ league_id: id })
16
+ Api.get(path: build_path(PATH), filters: filters, result: result)
17
+ end
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end