module Ropenweather::Agent

Public Instance Methods

execute(city:, action:, config:) click to toggle source
# File lib/ropenweather/agent.rb, line 7
def execute(city:, action:, config:)
  query = encode_query({ q: city }.merge(config))
  url = "#{base_uri}/#{action}?#{query}"

  response = RestClient.get(url)

  JSON.parse(response, symbolize_names: true)

rescue => exception
  # TODO: Isolate Exception handler in method
  message = exception.message

  case exception.class.to_s

  when 'RestClient::NotFound'
    raise CityNotFound, message
  when 'RestClient::Unauthorized'
    raise Unauthorized, message
  else
    raise StandardError, message
  end
end

Private Instance Methods

encode_query(params = {}) click to toggle source
# File lib/ropenweather/agent.rb, line 32
def encode_query(params = {})
  RestClient::Utils.encode_query_string params
end