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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/weather.rb +10 -5
  3. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c2ff5b98eb8a2df296d044935db90b2fd4057e4
4
- data.tar.gz: 52233aef1594f0685b342e3c571d195cbe9fb3fd
3
+ metadata.gz: 206659c255e4dfdb4e7cbb81127c1a0157a02441
4
+ data.tar.gz: b5cfeddfda20f2257f42b65d2162004f3f471205
5
5
  SHA512:
6
- metadata.gz: 4c7d9e393040ad97a32d3820c04f3b553c811af1a531a39254f12f721effb58ef12d4affecd56381abbae2b09464af6d0606d2ee8723843832ee8916bba36899
7
- data.tar.gz: 903104927c859d66be00845f40b91a8c23e750c043d0d7789893be44f24e4b2686c497435b994595b4cb8968c2db20b40b7c1d26430038bdc7ccf8467785cb02
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
- "Now in #{location} the weather is: " + openweather_situation(location)['weather'][0]['description']
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 openweather_situation(location)
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
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: weather-mg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Matteo Giaccone