Class: OpenMeteo::ResponseWrapper
- Inherits:
-
Object
- Object
- OpenMeteo::ResponseWrapper
- Defined in:
- lib/open_meteo/response_wrapper.rb
Overview
Wrap the JSON body response from the OpenMeteo request.
Instance Method Summary collapse
-
#initialize(config: OpenMeteo::Client::Config.new) ⇒ ResponseWrapper
constructor
A new instance of ResponseWrapper.
- #wrap(response, entity:) ⇒ Object
Constructor Details
#initialize(config: OpenMeteo::Client::Config.new) ⇒ ResponseWrapper
Returns a new instance of ResponseWrapper.
6 7 8 |
# File 'lib/open_meteo/response_wrapper.rb', line 6 def initialize(config: OpenMeteo::Client::Config.new) @config = config end |
Instance Method Details
#wrap(response, entity:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/open_meteo/response_wrapper.rb', line 10 def wrap(response, entity:) raise OpenMeteo::Errors::ResponseError, "Empty body" if response.body.nil? json_body = JSON.parse(response.body) check_for_error(response, json_body) entity.new(json_body) rescue JSON::ParserError raise OpenMeteo::Errors::ResponseError, "Unable to parse the response body: #{response.body}" end |