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
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/countries'
3
+ require 'football/butler/football_data/areas'
4
+ require 'football/butler/api_football/countries'
5
+
6
+ module Football
7
+ module Butler
8
+ class Countries < Areas
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/events'
3
+ require 'football/butler/football_data/matches'
4
+ require 'football/butler/api_football/fixtures'
5
+
6
+ module Football
7
+ module Butler
8
+ class Events < Matches
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,11 @@
1
+ # frozen_string_literal: true
2
+ require 'football/butler/apifootball/events'
3
+ require 'football/butler/football_data/matches'
4
+ require 'football/butler/api_football/fixtures'
5
+
6
+ module Football
7
+ module Butler
8
+ class Fixtures < Matches
9
+ end
10
+ end
11
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Football
4
+ module Butler
5
+ module FootballData
6
+ class Areas < Base
7
+ PATH = :areas
8
+
9
+ class << self
10
+ ## AREA
11
+ # v2/areas/{id}
12
+ # returns area object directly as a hash
13
+ def by_id(id:)
14
+ path = "#{PATH}/#{id}"
15
+ Api.get(path: path)
16
+ end
17
+
18
+ ## AREAS
19
+ # v2/areas
20
+ def all(result:)
21
+ Api.get(path: PATH, result: result)
22
+ end
23
+
24
+ ## ADDITIONAL
25
+ # v2/areas
26
+ # v2/areas/{id}
27
+ # returns area object directly as a hash
28
+ def by_name(name:, result:, filters:)
29
+ areas = all(result: PATH)
30
+ return areas if areas.is_a?(Hash) && areas.with_indifferent_access.dig('message')
31
+ area = areas&.detect { |area| area['name'] == name }
32
+ return not_found_result(name) unless area
33
+
34
+ by_id(id: area['id'])
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,72 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Football
4
+ module Butler
5
+ module FootballData
6
+ class Competitions < Base
7
+ PATH = :competitions
8
+
9
+ class << self
10
+ ## COMPETITION
11
+ # v2/competitions/{id}
12
+ # returns competition object directly as a hash
13
+ def by_id(id:)
14
+ path = "#{PATH}/#{id}"
15
+ Api.get(path: path)
16
+ end
17
+
18
+ ## COMPETITIONS
19
+ #
20
+ # areas={AREAS}
21
+ # plan={PLAN}
22
+ #
23
+ # v2/competitions
24
+ def all(result:, filters: Configuration.tier_plan_filter)
25
+ Api.get(path: PATH, result: result, filters: filters)
26
+ end
27
+
28
+ # v2/competitions
29
+ def all_tier_plan_filter(result:, filters:)
30
+ Api.get(path: PATH, result: result, filters: filters)
31
+ end
32
+
33
+ # v2/competitions?plan={plan}
34
+ def by_plan(plan:, result:, filters:)
35
+ filters.merge!({ plan: plan })
36
+ Api.get(path: PATH, result: result, filters: filters)
37
+ end
38
+
39
+ # v2/competitions?areas={id1, id2, ...}
40
+ def by_areas(ids:, result:, filters:)
41
+ filters.merge!({ areas: ids.join(',') })
42
+ Api.get(path: PATH, result: result, filters: filters)
43
+ end
44
+
45
+ ## ADDITIONAL
46
+ # v2/competitions/{id}
47
+ def current_match_day(id:)
48
+ response = by_id(id:id)
49
+
50
+ if response.is_a?(Hash) && response.dig('message')
51
+ response
52
+ else
53
+ response['currentSeason']['currentMatchday']
54
+ end
55
+ end
56
+
57
+ # v2/competitions/{id}
58
+ def seasons(id:)
59
+ response = by_id(id:id)
60
+
61
+ if response.is_a?(Hash) && response.dig('message')
62
+ response
63
+ else
64
+ response['seasons']
65
+ end
66
+ end
67
+ end
68
+
69
+ end
70
+ end
71
+ end
72
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Football
4
+ module Butler
5
+ module FootballData
6
+ class HeadToHead < Base
7
+ PATH = :matches
8
+
9
+ class << self
10
+ ## HEAD TO HEAD
11
+ #
12
+ # v2/matches/{id}
13
+ def by_match(id:)
14
+ path = "#{PATH}/#{id}"
15
+ match = Api.get(path: path, result: :parsed_response)
16
+
17
+ if match.is_a?(Hash) && match.with_indifferent_access.dig(:head2head)
18
+ match['head2head']
19
+ else
20
+ match
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,32 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Football
4
+ module Butler
5
+ module FootballData
6
+ class Lineups < Base
7
+ PATH = :matches
8
+
9
+ class << self
10
+ ## LINEUPS
11
+ #
12
+ # v2/matches/{id}
13
+ def by_match(id:)
14
+ path = "#{PATH}/#{id}"
15
+ match = Api.get(path: path, result: :match)
16
+
17
+ if match.is_a?(Hash) && match.with_indifferent_access.dig(:homeTeam) &&
18
+ match.with_indifferent_access.dig(:awayTeam)
19
+
20
+ lineups = {}
21
+ lineups['homeTeam'] = match['homeTeam']
22
+ lineups['awayTeam'] = match['awayTeam']
23
+ lineups
24
+ else
25
+ match
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
@@ -0,0 +1,110 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Football
4
+ module Butler
5
+ module FootballData
6
+ class Matches < Base
7
+ PATH = :matches
8
+ STATUS_SCHEDULED = 'SCHEDULED'
9
+ STATUS_FINISHED = 'FINISHED'
10
+
11
+ class << self
12
+ ## MATCH
13
+ # v2/matches/{id}
14
+ # returns ["head2head", "match"]
15
+ def by_id(id:)
16
+ path = "#{PATH}/#{id}"
17
+ Api.get(path: path)
18
+ end
19
+
20
+ ## MATCHES
21
+ #
22
+ # competitions={competitionIds}
23
+ # dateFrom={DATE}
24
+ # dateTo={DATE}
25
+ # status={STATUS}
26
+ #
27
+ # /v2/matches
28
+ def all(result:, filters:)
29
+ Api.get(path: PATH, result: result, filters: filters)
30
+ end
31
+
32
+ ## by COMPETITION
33
+ #
34
+ # dateFrom={DATE}
35
+ # dateTo={DATE}
36
+ # stage={STAGE}
37
+ # status={STATUS}
38
+ # matchday={MATCHDAY}
39
+ # group={GROUP}
40
+ # season={YEAR}
41
+ #
42
+ # v2/competitions/{id}/matches
43
+ def by_competition(id:, result:, filters:)
44
+ path = "#{Competitions::PATH}/#{id}/#{PATH}"
45
+ Api.get(path: path, filters: filters, result: result)
46
+ end
47
+
48
+ # v2/competitions/{id}/matches?season={year}
49
+ def by_competition_and_year(id:, year:, result:, filters:)
50
+ path = "#{Competitions::PATH}/#{id}/#{PATH}"
51
+ filters.merge!({ season: year })
52
+ Api.get(path: path, filters: filters, result: result)
53
+ end
54
+
55
+ # v2/competitions/{id}/matches?matchday={match_day}
56
+ def by_competition_and_match_day(id:, match_day:, result:, filters:)
57
+ path = "#{Competitions::PATH}/#{id}/#{PATH}"
58
+ filters.merge!({ matchday: match_day })
59
+ Api.get(path: path, filters: filters, result: result)
60
+ end
61
+
62
+ ## by TEAM
63
+ #
64
+ # dateFrom={DATE}
65
+ # dateTo={DATE}
66
+ # status={STATUS}
67
+ # venue={VENUE}
68
+ # limit={LIMIT}
69
+ #
70
+ # v2/teams/{id}/matches
71
+ def by_team(id:, result:, filters:)
72
+ path = "#{Teams::PATH}/#{id}/#{PATH}"
73
+ Api.get(path: path, result: result, filters: filters)
74
+ end
75
+
76
+ # v2/teams/{id}/matches?status={status}
77
+ def by_team_and_status(id:, status:, result:, filters:)
78
+ path = "#{Teams::PATH}/#{id}/#{PATH}"
79
+ filters.merge!({ status: status })
80
+ Api.get(path: path, result: result, filters: filters)
81
+ end
82
+
83
+ # v2/teams/{team}/matches?status=FINISHED
84
+ def by_team_finished(id:, result:, filters:)
85
+ by_team_and_status(id: id, status: STATUS_FINISHED, result: result, filters: filters)
86
+ end
87
+
88
+ # v2/teams/{team}/matches?status=SCHEDULED
89
+ def by_team_scheduled(id:, result:, filters:)
90
+ by_team_and_status(id: id, status: STATUS_SCHEDULED, result: result, filters: filters)
91
+ end
92
+
93
+ ## PLAYER
94
+ #
95
+ # dateFrom={DATE}
96
+ # dateTo={DATE}
97
+ # status={STATUS}
98
+ # competitions={competitionIds}
99
+ # limit={LIMIT}
100
+ #
101
+ # /v2/players/{id}/matches
102
+ def by_player(id:, result:, filters:)
103
+ path = "#{Players::PATH}/#{id}/#{PATH}"
104
+ Api.get(path: path, result: result, filters: filters)
105
+ end
106
+ end
107
+ end
108
+ end
109
+ end
110
+ end
@@ -0,0 +1,27 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Football
4
+ module Butler
5
+ module FootballData
6
+ class Odds < Base
7
+ PATH = :matches
8
+
9
+ class << self
10
+ ## ODDS
11
+ #
12
+ # v2/matches/{id}
13
+ def by_match(id:, from:, to:, result:)
14
+ path = "#{PATH}/#{id}"
15
+ match = Api.get(path: path, result: :match)
16
+
17
+ if match.is_a?(Hash) && match.with_indifferent_access.dig(:odds)
18
+ match['odds']
19
+ else
20
+ match
21
+ end
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
27
+ end
@@ -0,0 +1,20 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Football
4
+ module Butler
5
+ module FootballData
6
+ class Players < Base
7
+ PATH = :players
8
+
9
+ class << self
10
+ ## PLAYER
11
+ # v2/players/{id}
12
+ def by_id(id:)
13
+ path = "#{PATH}/#{id}"
14
+ Api.get(path: path)
15
+ end
16
+ end
17
+ end
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Football
4
+ module Butler
5
+ module FootballData
6
+ class Scorers < Base
7
+ PATH = :scorers
8
+
9
+ class << self
10
+ ## SCORER
11
+ #
12
+ # limit={LIMIT}
13
+ #
14
+ # /v2/competitions/{id}/scorers
15
+ def by_competition(id:, filters:, result:)
16
+ path = "#{Competitions::PATH}/#{id}/#{PATH}"
17
+ Api.get(path: path, result: result, filters: filters)
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Football
4
+ module Butler
5
+ module FootballData
6
+ class Standings < Base
7
+ PATH = :standings
8
+
9
+ STANDING_TYPE_HOME = 'HOME'
10
+ STANDING_TYPE_AWAY = 'AWAY'
11
+
12
+ ## STANDINGS
13
+ #
14
+ # season={YEAR}
15
+ # standingType={standingType}
16
+ # standingType: [ TOTAL (default) | HOME | AWAY ]
17
+ #
18
+ # v2/competitions/{id}/standings
19
+ class << self
20
+ def by_competition(id:, result:, filters:)
21
+ path = "#{Competitions::PATH}/#{id}/#{PATH}"
22
+ Api.get(path: path, filters: filters, result: result)
23
+ end
24
+
25
+ # v2/competitions/{id}/standings?standingType=HOME
26
+ def home_by_competition(id:, result:, filters:)
27
+ filters.merge!({ standingType: STANDING_TYPE_HOME })
28
+ by_competition(id: id, filters: filters, result: result)
29
+ end
30
+
31
+ # v2/competitions/{id}/standings?standingType=AWAY
32
+ def away_by_competition(id:, result:, filters:)
33
+ filters.merge!({ standingType: STANDING_TYPE_AWAY })
34
+ by_competition(id: id, filters: filters, result: result)
35
+ end
36
+
37
+ # v2/competitions/{id}/standings
38
+ def by_competition_and_year(id:, year:, result:, filters:)
39
+ path = "#{Competitions::PATH}/#{id}/#{PATH}"
40
+ filters.merge!({ season: year })
41
+ Api.get(path: path, filters: filters, result: result)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end