Class: Sports::Butler::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/sports/butler/base.rb

Direct Known Subclasses

Basketball, Soccer

Constant Summary collapse

ALIASES =
{
  areas: :countries,
  leagues: :competitions,
  events: :matches,
  fixtures: :matches,
  top_scorers: :scorers
}
AVAILABLE_ENDPOINTS =
{
  soccer: {},
  basketball: {}
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sport:, api_name:) ⇒ Base

Returns a new instance of Base.



64
65
66
67
68
69
70
71
72
73
74
# File 'lib/sports/butler/base.rb', line 64

def initialize(sport:, api_name:)
  @sport        = sport
  @api_name     = api_name
  @api_class    = api_name.to_s.camelize
  @sport_class  = "#{sport.to_s.camelize}Api"

  @endpoints    = {}

  @available_endpoints  = get_available_endpoints
  @valid_configuration  = !Configuration.invalid_config?(sport, api_name)
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method, *args, &block) ⇒ Object



76
77
78
79
80
81
82
83
84
# File 'lib/sports/butler/base.rb', line 76

def method_missing(method, *args, &block)
  endpoint_name = eval_endpoint_name(method)
  if endpoint_name.present?
    @endpoints[method].present? ?
      @endpoints[method] : @endpoints[method] = build_endpoint_classes(endpoint_name)
  else
    raise MissingEndpoint, endpoint_not_available(method)
  end
end

Instance Attribute Details

#api_classObject

Returns the value of attribute api_class.



61
62
63
# File 'lib/sports/butler/base.rb', line 61

def api_class
  @api_class
end

#api_nameObject

Returns the value of attribute api_name.



61
62
63
# File 'lib/sports/butler/base.rb', line 61

def api_name
  @api_name
end

#available_endpointsObject

Returns the value of attribute available_endpoints.



61
62
63
# File 'lib/sports/butler/base.rb', line 61

def available_endpoints
  @available_endpoints
end

#endpointsObject

Returns the value of attribute endpoints.



61
62
63
# File 'lib/sports/butler/base.rb', line 61

def endpoints
  @endpoints
end

#sportObject

Returns the value of attribute sport.



61
62
63
# File 'lib/sports/butler/base.rb', line 61

def sport
  @sport
end

#sport_classObject

Returns the value of attribute sport_class.



61
62
63
# File 'lib/sports/butler/base.rb', line 61

def sport_class
  @sport_class
end

#valid_configurationObject

Returns the value of attribute valid_configuration.



61
62
63
# File 'lib/sports/butler/base.rb', line 61

def valid_configuration
  @valid_configuration
end