Module: NoaaWeatherClient::RestService
- Included in:
- Services::CurrentObservations, Services::PostalCodeToCoordinate, Services::WeatherStations
- Defined in:
- lib/noaa_weather_client/services/rest_service.rb
Instance Method Summary collapse
- #build_request_for_action(action, url, options = {}) ⇒ Object
- #object_from_response(action, url, options = {}) ⇒ Object
Instance Method Details
#build_request_for_action(action, url, options = {}) ⇒ Object
Note:
Much more to be done here when needed.
21 22 23 24 25 26 |
# File 'lib/noaa_weather_client/services/rest_service.rb', line 21 def build_request_for_action(action, url, = {}) r_class = case action when :get then Net::HTTP::Get end r_class.new url end |
#object_from_response(action, url, options = {}) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 |
# File 'lib/noaa_weather_client/services/rest_service.rb', line 8 def object_from_response(action, url, = {}) response_class = .fetch(:response_class, Responses::GenericResponse) client = .fetch(:client) { RestClientFactory.build_client(url: url) } request = build_request_for_action action, url, response_class.new client.request(request).body rescue Net::HTTPError, Net::HTTPRetriableError, Net::HTTPServerException, Net::HTTPFatalError => e raise Errors::CommunicationError, e., e.backtrace end |