Class: Football::Butler::Base

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

Constant Summary collapse

MSG_INVALID_CONFIG =
'Invalid Configuration, check empty api_token or empty / invalid api_endpoint!'

Class Method Summary collapse

Class Method Details

.api_classObject



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

def api_class
  Configuration.api_class
end

.api_switchObject



55
56
57
58
59
# File 'lib/football/butler/base.rb', line 55

def api_switch
  "Football::Butler::#{api_class}::#{this_class}".constantize
rescue
  return nil
end

.api_switch_method(method, named_params) ⇒ Object

MULTI-API



39
40
41
42
43
44
45
46
47
48
49
# File 'lib/football/butler/base.rb', line 39

def api_switch_method(method, named_params)
  klass = api_switch

  if klass
    klass.respond_to?(method) ?
      klass.send(method, **named_params) :
      unsupported_api_call(this_class, method)
  else
    unsupported_api_endpoint(this_class)
  end
end

.api_switch_resultObject



51
52
53
# File 'lib/football/butler/base.rb', line 51

def api_switch_result
  Configuration.api_result(api_switch)
end

.error_message(error) ⇒ Object



34
35
36
# File 'lib/football/butler/base.rb', line 34

def error_message(error)
  { message: error }.with_indifferent_access
end

.invalid_config_resultObject



20
21
22
# File 'lib/football/butler/base.rb', line 20

def invalid_config_result
  error_message(MSG_INVALID_CONFIG)
end

.not_found_result(*params) ⇒ Object

RESULT MESSAGES



16
17
18
# File 'lib/football/butler/base.rb', line 16

def not_found_result(*params)
  error_message("#{params.join(', ')} could not be found.")
end

.reached_limit?(response) ⇒ Boolean

MESSAGES

Returns:

  • (Boolean)


11
12
13
# File 'lib/football/butler/base.rb', line 11

def reached_limit?(response)
  Configuration.reached_limit?(response)
end

.this_classObject



65
66
67
68
# File 'lib/football/butler/base.rb', line 65

def this_class
  klass = self.to_s.split('::').last
  Configuration.class_converter(klass)
end

.unsupported_api_call(klass, method) ⇒ Object



24
25
26
27
28
# File 'lib/football/butler/base.rb', line 24

def unsupported_api_call(klass, method)
  message  = "Method '#{method}' is not supported for the endpoint '#{klass}' by this API: "
  message += "#{Configuration.api_name}"
  error_message(message)
end

.unsupported_api_endpoint(klass) ⇒ Object



30
31
32
# File 'lib/football/butler/base.rb', line 30

def unsupported_api_endpoint(klass)
  error_message("The Endpoint '#{klass}' is not supported by this API: #{Configuration.api_name}")
end