open_weather_map 0.0.1 → 0.0.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1bc2a83b9d8f696af9c44878c24692b81d0dd27d
4
- data.tar.gz: d9b79c0cd257ae8b972c1158f821a07691fffba8
3
+ metadata.gz: 59ea46a0cb6452e495fcccc81b6f190c92b1e70f
4
+ data.tar.gz: abe72eb398b6678ebe56492d10f47d5435feb50b
5
5
  SHA512:
6
- metadata.gz: 2fe1a845fc6d3569ed07927d1d41338804c560a2509a4a7ac517f18b0633894752d6880c300f06286d95c15a22ed9a2b88df20eb31a191eddf4af827321b284e
7
- data.tar.gz: 42e1c59ac2892748d44ee0a152393f01b47196b17644d1ec4e00624e45d20acf0d62cfd890d54c7f0c2122103b48a37526f50ad75f5cc76914cca3ff2333be8a
6
+ metadata.gz: 2a9b14651ecdd0b86c98ce1154fa47258b582d98577f6345764603c037826796df2c10376123992d6287ddcdae46302ea6627dc82f7975b10f3195009bd478fa
7
+ data.tar.gz: 82748a48b2ab318284737b563aad32a60e31a4a1f109e704826ae348a2fb2d2972315332a162d781651b12f7def5f2685bf2cb1f08db9a56f0cfc64e63854770
@@ -0,0 +1,38 @@
1
+ require 'rest_client'
2
+ module OpenWeatherMap
3
+ URL = 'http://api.openweathermap.org/data/2.5/weather'
4
+ class Base
5
+
6
+ def cond
7
+ @response['weather'][0]['main']
8
+ end
9
+
10
+ def temp_min
11
+ @response['main']['temp_min']
12
+ end
13
+
14
+ def temp_max
15
+ @response['main']['temp_max']
16
+ end
17
+
18
+ def temp_min_celsius
19
+ to_celsius @response['main']['temp_min']
20
+ end
21
+
22
+ def temp_max_celsius
23
+ to_celsius @response['main']['temp_max']
24
+ end
25
+
26
+ private
27
+ def request(params)
28
+ response = RestClient.get OpenWeatherMap::URL, { params: params }
29
+ JSON.parse(response)
30
+ end
31
+
32
+ def to_celsius(temp)
33
+ (temp.to_f - 273.15).round(1)
34
+ end
35
+
36
+ end
37
+ end
38
+
@@ -1,3 +1,3 @@
1
1
  module OpenWeatherMap
2
- VERSION = "0.0.1"
2
+ VERSION = "0.0.2"
3
3
  end
@@ -1,44 +1,20 @@
1
1
  require 'open_weather_map/version'
2
- require 'rest_client'
2
+ require 'open_weather_map/base'
3
3
 
4
4
  module OpenWeatherMap
5
- URL = 'http://api.openweathermap.org/data/2.5/weather'
6
- class City
5
+ class City < Base
7
6
  def initialize(country, city)
8
7
  params = { q: "#{country},#{city}" }
9
8
  @response = request params
10
9
  end
11
10
 
12
- def cond
13
- @response['weather'][0]['main']
14
- end
15
-
16
- def temp_min
17
- @response['main']['temp_min']
18
- end
19
-
20
- def temp_max
21
- @response['main']['temp_max']
22
- end
23
-
24
- private
25
- def request(params)
26
- response = RestClient.get OpenWeatherMap::URL, { params: params }
27
- JSON.parse(response)
28
- end
29
-
30
11
  end
31
12
 
32
- class Geocode
13
+ class Geocode < Base
33
14
  def initialize(lat, lon)
34
15
  params = { lat: lat, lon: lon }
35
- request params
16
+ @response = request params
36
17
  end
37
18
 
38
- private
39
- def request(params)
40
- response = RestClient.get OpenWeatherMap::URL, { params: params }
41
- JSON.parse(response)
42
- end
43
19
  end
44
20
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_weather_map
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - otukutun
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-01-01 00:00:00.000000000 Z
11
+ date: 2015-01-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -81,6 +81,7 @@ files:
81
81
  - README.md
82
82
  - Rakefile
83
83
  - lib/open_weather_map.rb
84
+ - lib/open_weather_map/base.rb
84
85
  - lib/open_weather_map/version.rb
85
86
  - open_weather_map.gemspec
86
87
  - spec/open_weather_map_spec.rb