Class: Sports::Butler::SoccerApi::FootballDataOrg::Countries

Inherits:
Countries show all
Includes:
Base
Defined in:
lib/sports/butler/soccer_api/football_data_org/countries.rb

Instance Attribute Summary

Attributes inherited from Endpoints

#api, #api_name, #sport

Instance Method Summary collapse

Methods included from Base

#api_with_id, #path_with_id

Methods inherited from Base

#error_message, #method_missing, #not_found_result

Methods inherited from Endpoints

#build_path, #error_missing_endpoint_method, #filters_by_competition, #filters_by_competition_and_year, #filters_by_id, #filters_by_match, #filters_by_player, #filters_by_team, #filters_search_by_name, #initialize

Methods included from Sports::Butler::Shared::ApiComs

#cups, #leagues

Methods included from Sports::Butler::Shared::AllSports

#all, #by_coach, #by_code, #by_competition, #by_competition_and_range, #by_competition_and_season, #by_competition_and_team_and_season, #by_competition_and_year, #by_country, #by_country_name, #by_id_and_season, #by_match, #by_player, #by_season, #by_team, #by_team_and_range, #by_team_and_season, #by_teams, #search_by_name

Constructor Details

This class inherits a constructor from Sports::Butler::Endpoints

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Sports::Butler::SoccerApi::Base

Instance Method Details

#available_endpoint_methodsObject



11
12
13
# File 'lib/sports/butler/soccer_api/football_data_org/countries.rb', line 11

def available_endpoint_methods
  [:all, :by_name, :by_id]
end

#by_id(id:, filters: {}) ⇒ Object



19
20
21
# File 'lib/sports/butler/soccer_api/football_data_org/countries.rb', line 19

def by_id(id:, filters: {})
  api_with_id(id, filters)
end

#by_name(name:, _filters: {}) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/sports/butler/soccer_api/football_data_org/countries.rb', line 23

def by_name(name:, _filters: {})
  api = all

  return api if api.parsed_response.is_a?(Hash) &&
    api.parsed_response.with_indifferent_access.dig('message')

  country = api.parsed_response['areas'].detect { |area| area['name'] == name }

  if country
    by_id(id: country['id'])
  else
    api.parsed_response = not_found_result(name)
    api
  end

end

#pathObject



15
16
17
# File 'lib/sports/butler/soccer_api/football_data_org/countries.rb', line 15

def path
  :areas
end