Class: OpenWeatherAPI::Resources::Base
- Inherits:
-
Object
- Object
- OpenWeatherAPI::Resources::Base
- Defined in:
- lib/open-weather-api/resources/base_resource.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_resource.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_resource.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 |
# File 'lib/open-weather-api/resources/base_resource.rb', line 11 def execute(**hash, &block) @parameters = hash setup_indifferent_access(@parameters) response = request raise "Invalid response." unless response.code == 200 json = JSON.parse(response.body) return block.call(json) if block_given? json end |