9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/darksky_weather/api/client.rb', line 9
def get_weather(lat:, lng:, timestamp: nil, opts: {})
key = DarkskyWeather::Api.configuration.api_key
request_path = "/#{key}/#{lat},#{lng}"
request_path << ",#{timestamp}" if timestamp
allowed_opts = %w(extend exclude lang units)
opts.each_with_index do |o, idx|
next unless allowed_opts.include?(o.first.to_s)
sep_sym = idx == 0 ? '?' : '&'
request_path << "#{sep_sym}#{o.first}=#{o.last}"
end
raw_result = self.class.get(request_path)
request_uri = raw_result.request.uri.to_s
return WeatherData.new(timestamp, request_uri, raw_result.parsed_response)
end
|