Class: OpenWeatherAPI::Resources::Base
- Inherits:
-
Object
- Object
- OpenWeatherAPI::Resources::Base
- Defined in:
- lib/open-weather-api/resources/base.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#api_obj ⇒ Object
readonly
Returns the value of attribute api_obj.
Instance Method Summary collapse
- #execute(**hash, &block) ⇒ Object
-
#initialize(api_obj) ⇒ Base
constructor
A new instance of Base.
Constructor Details
#initialize(api_obj) ⇒ Base
Returns a new instance of Base.
7 8 9 |
# File 'lib/open-weather-api/resources/base.rb', line 7 def initialize(api_obj) @api_obj = api_obj end |
Instance Attribute Details
#api_obj ⇒ Object (readonly)
Returns the value of attribute api_obj.
5 6 7 |
# File 'lib/open-weather-api/resources/base.rb', line 5 def api_obj @api_obj end |
Instance Method Details
#execute(**hash, &block) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/open-weather-api/resources/base.rb', line 11 def execute(**hash, &block) @parameters = hash setup_indifferent_access(@parameters) # Let's use json response = RestClient.send :get, base_url, params: build_params(@parameters) raise "Invalid response." unless response.code == 200 # Handle the response format response = self.send "handle_response_#{mode}", response # Handle the block return block.call(response) if block_given? response end |