Class: OpenWeatherAPI::Resources::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/open-weather-api/resources/base_resource.rb

Direct Known Subclasses

Current

Instance Attribute Summary collapse

Instance Method Summary collapse

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_objObject (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