7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
|
# 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
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
|