-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathweathers.rb
51 lines (38 loc) · 1.11 KB
/
weathers.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
class Weathers
attr_reader :lat, :lon, :description, :temperature
def initialize(lat, lon)
@lat = lat
@lon = lon
display_weather
end
def call_open_weather_api(url)
json_response = HTTParty.get(url).body
return JSON.parse( json_response )
end
def display_weather
url = "http://api.openweathermap.org/data/2.5/weather?lat="[email protected]_s+"&lon="[email protected]_s+"&type=like&units=imperial"
parsed_weather_result = call_open_weather_api(url)
#pp parsed_weather_result
parsed_weather_result['weather'].each do |result|
if result['description'] != nil
@description = result['description']
end
end
#puts 'description:'+ @description
if parsed_weather_result['main']['temp'] != nil
@temperature = parsed_weather_result['main']['temp']
end
#puts 'temperature:'+ @temperature.to_s
# @weatherStatus = "It is currently #{temp} and #{@description} outside."
end
end
# #get '/weather' do
# @lat = params[:lat]
# @lon = params[:lon]
#
# weather = Weathers.new(@lat, @lon)
# @weatherStatus = weather.weatherStatus
#
# erb :weather
#
# end