weather-mg 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/weather.rb +10 -5
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 206659c255e4dfdb4e7cbb81127c1a0157a02441
|
4
|
+
data.tar.gz: b5cfeddfda20f2257f42b65d2162004f3f471205
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ce57ace508fdb1fef090de8a0728599ff2bf59d07e224b2053c45da4cb32fbf563ebb01a944ccaa063ce4bed17631f6d466ea84e9e4653a0e4eded5195a58b13
|
7
|
+
data.tar.gz: 96f18176dd4df394662dcf16f4f28340f32009d9c0dc9f94d2345e4f8f62112aea96051f6d674dbe22b932a5a8ecdec15bafd73ec02f3aa5a55932be1c8e0390
|
data/lib/weather.rb
CHANGED
@@ -3,17 +3,22 @@ require 'json'
|
|
3
3
|
|
4
4
|
class Weather
|
5
5
|
def initialize
|
6
|
-
|
7
6
|
end
|
8
7
|
|
9
|
-
def query(location)
|
10
|
-
|
8
|
+
def query(location = '')
|
9
|
+
current_situation = current_situation(location)
|
10
|
+
if current_situation['cod'] == '404'
|
11
|
+
'Sorry, no location found for you'
|
12
|
+
else
|
13
|
+
"Now in #{location} the weather is: " +
|
14
|
+
current_situation['weather'][0]['description']
|
15
|
+
end
|
11
16
|
end
|
12
17
|
|
13
18
|
private
|
14
19
|
|
15
|
-
def
|
16
|
-
@situation ||= JSON.load(open("http://api.openweathermap.org/data/2.5/weather?q=#{location}"))
|
20
|
+
def current_situation(location)
|
21
|
+
@situation ||= JSON.load(open(URI.encode("http://api.openweathermap.org/data/2.5/weather?q=#{location}")))
|
17
22
|
end
|
18
23
|
end
|
19
24
|
|