Class: Football::Butler::FootballData::Competitions

Inherits:
Base
  • Object
show all
Defined in:
lib/football/butler/football_data/competitions.rb

Constant Summary collapse

PATH =
:competitions

Constants inherited from Base

Base::MSG_INVALID_CONFIG

Class Method Summary collapse

Methods inherited from Base

api_class, api_switch, api_switch_method, api_switch_result, error_message, invalid_config_result, not_found_result, reached_limit?, this_class, unsupported_api_call, unsupported_api_endpoint

Class Method Details

.all(result:, filters: Configuration.tier_plan_filter) ⇒ Object

COMPETITIONS

areas=AREAS plan=PLAN

v2/competitions



24
25
26
# File 'lib/football/butler/football_data/competitions.rb', line 24

def all(result:, filters: Configuration.tier_plan_filter)
  Api.get(path: PATH, result: result, filters: filters)
end

.all_tier_plan_filter(result:, filters:) ⇒ Object

v2/competitions



29
30
31
# File 'lib/football/butler/football_data/competitions.rb', line 29

def all_tier_plan_filter(result:, filters:)
  Api.get(path: PATH, result: result, filters: filters)
end

.by_areas(ids:, result:, filters:) ⇒ Object

v2/competitions?areas=id2, …



40
41
42
43
# File 'lib/football/butler/football_data/competitions.rb', line 40

def by_areas(ids:, result:, filters:)
  filters.merge!({ areas: ids.join(',') })
  Api.get(path: PATH, result: result, filters: filters)
end

.by_id(id:) ⇒ Object

COMPETITION v2/competitions/id returns competition object directly as a hash



13
14
15
16
# File 'lib/football/butler/football_data/competitions.rb', line 13

def by_id(id:)
  path = "#{PATH}/#{id}"
  Api.get(path: path)
end

.by_plan(plan:, result:, filters:) ⇒ Object

v2/competitions?plan=plan



34
35
36
37
# File 'lib/football/butler/football_data/competitions.rb', line 34

def by_plan(plan:, result:, filters:)
  filters.merge!({ plan: plan })
  Api.get(path: PATH, result: result, filters: filters)
end

.current_match_day(id:) ⇒ Object

ADDITIONAL v2/competitions/id



47
48
49
50
51
52
53
54
55
# File 'lib/football/butler/football_data/competitions.rb', line 47

def current_match_day(id:)
  response = by_id(id:id)

  if response.is_a?(Hash) && response.dig('message')
    response
  else
    response['currentSeason']['currentMatchday']
  end
end

.seasons(id:) ⇒ Object

v2/competitions/id



58
59
60
61
62
63
64
65
66
# File 'lib/football/butler/football_data/competitions.rb', line 58

def seasons(id:)
  response = by_id(id:id)

  if response.is_a?(Hash) && response.dig('message')
    response
  else
    response['seasons']
  end
end