Class: Football::Butler::Base
- Inherits:
-
Object
- Object
- Football::Butler::Base
show all
- Defined in:
- lib/football/butler/base.rb
Direct Known Subclasses
Api, ApiFootball::BaseApiFootball, ApiFootball::HeadToHead, Apifootball::BaseApifootball, Areas, Coachs, Competitions, FootballData::Areas, FootballData::Competitions, FootballData::HeadToHead, FootballData::Lineups, FootballData::Matches, FootballData::Odds, FootballData::Players, FootballData::Scorers, FootballData::Standings, FootballData::Teams, HeadToHead, Injuries, Lineups, Matches, Odds, Players, Predictions, Scorers, Sidelineds, Standings, Statistics, Teams, Timezones, Transfers, Trophies, Venues
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_switch ⇒ Object
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
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_result ⇒ Object
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_result ⇒ Object
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
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
.this_class ⇒ Object
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
|