Class: IRacingAPI::Client
- Inherits:
-
Object
- Object
- IRacingAPI::Client
- Defined in:
- lib/iracing_api.rb
Constant Summary collapse
- BASE_URL =
"https://members-ng.iracing.com/"
Instance Method Summary collapse
-
#initialize(email, password) ⇒ Client
constructor
A new instance of Client.
- #method_missing(m, *args, &block) ⇒ Object
Constructor Details
#initialize(email, password) ⇒ Client
Returns a new instance of Client.
14 15 16 17 18 |
# File 'lib/iracing_api.rb', line 14 def initialize(email, password) @email, @password = email, password authenticate! load_schema! end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(m, *args, &block) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/iracing_api.rb', line 20 def method_missing(m, *args, &block) if @schema.keys.include?(m.to_s) if @schema[m.to_s].dig('get', 'parameters') available_params = @schema[m.to_s]['get']['parameters'] required_params = available_params.select{|k,v| v.dig('required') == true }.keys.collect{|k| k.to_sym } supplied_args = args.collect{|p| p.keys.collect{|k| k.to_sym }}.flatten unless (required_params - supplied_args).empty? raise "The following params must be supplied: #{required_params}" end end (@schema[m.to_s]['get']['link'], args.flatten[0]) else super end end |