open-weather 0.9.1 → 0.9.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +6 -0
- data/lib/open_weather/base.rb +7 -7
- data/lib/open_weather/version.rb +1 -1
- data/open_weather.gemspec +1 -3
- data/spec/open_weather/api_spec.rb +28 -10
- metadata +3 -19
data/README.md
CHANGED
@@ -25,11 +25,17 @@ Add the following to your **Gemfile**
|
|
25
25
|
# get current weather by geocode. (lat, lon)
|
26
26
|
OpenWeather::Current.geocode(9.94, 76.26)
|
27
27
|
|
28
|
+
# get the current weather in degrees celsius
|
29
|
+
OpenWeather::Current.city("Cochin, IN", units: 'metric')
|
30
|
+
|
28
31
|
# weather forecast APIs
|
29
32
|
|
30
33
|
# get weather forecast by city name
|
31
34
|
OpenWeather::Forecast.city("Cochin, IN")
|
32
35
|
|
36
|
+
# get weather forecast by city name in fahrenheit
|
37
|
+
OpenWeather::Forecast.city("Cochin, IN", units: 'imperial')
|
38
|
+
|
33
39
|
# get weather forecast by city id
|
34
40
|
OpenWeather::Forecast.city_id("1273874")
|
35
41
|
|
data/lib/open_weather/base.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
1
|
+
require 'net/http'
|
2
|
+
require 'json'
|
3
3
|
|
4
4
|
module OpenWeather
|
5
5
|
class Base
|
@@ -24,7 +24,7 @@ module OpenWeather
|
|
24
24
|
private
|
25
25
|
|
26
26
|
def extract_options!(options)
|
27
|
-
valid_options = [:lat, :lon, :city, :country, :id]
|
27
|
+
valid_options = [:lat, :lon, :city, :country, :id, :units]
|
28
28
|
options.keys.each { |k| options.delete(k) unless valid_options.include?(k) }
|
29
29
|
|
30
30
|
if options[:city] || options[:country]
|
@@ -37,16 +37,16 @@ module OpenWeather
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def parse_response
|
40
|
-
@weather_info = @response
|
40
|
+
@weather_info = JSON.parse(@response)
|
41
41
|
@status = @weather_info["cod"]
|
42
42
|
@message = @weather_info["message"] unless @status
|
43
43
|
@weather_info
|
44
44
|
end
|
45
45
|
|
46
46
|
def send_request(request)
|
47
|
-
uri =
|
48
|
-
uri.
|
49
|
-
|
47
|
+
uri = URI(request.url)
|
48
|
+
uri.query = URI.encode_www_form(request.options)
|
49
|
+
Net::HTTP.get(uri)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
end
|
data/lib/open_weather/version.rb
CHANGED
data/open_weather.gemspec
CHANGED
@@ -14,7 +14,5 @@ Gem::Specification.new do |gem|
|
|
14
14
|
gem.executables = gem.files.grep(/^bin/).map{ |f| File.basename(f) }
|
15
15
|
gem.require_paths = ["lib"]
|
16
16
|
gem.add_development_dependency "rspec"
|
17
|
-
|
18
|
-
gem.add_runtime_dependency 'httparty'
|
19
|
-
gem.add_runtime_dependency 'addressable'
|
17
|
+
gem.add_runtime_dependency 'json'
|
20
18
|
end
|
@@ -1,7 +1,7 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
# success response
|
4
|
-
#
|
4
|
+
#
|
5
5
|
# {"coord"=>{"lon"=>76.26, "lat"=>9.94},
|
6
6
|
# "sys"=>
|
7
7
|
# {"message"=>0.1938,
|
@@ -31,14 +31,6 @@ require 'spec_helper'
|
|
31
31
|
#
|
32
32
|
# {"message"=>"Error: Not found city", "cod"=>"404"}
|
33
33
|
|
34
|
-
describe 'Connection Error' do
|
35
|
-
it 'return error when the network is unreachable' do
|
36
|
-
response = OpenWeather::Current.city('Cochin, In')
|
37
|
-
response['cod'].should eq(200)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
|
41
|
-
|
42
34
|
describe 'Open weather Current API' do
|
43
35
|
context '.city' do
|
44
36
|
it 'return current weather for cochi' do
|
@@ -75,6 +67,19 @@ describe 'Open weather Current API' do
|
|
75
67
|
response['cod'].should eq("404")
|
76
68
|
end
|
77
69
|
end
|
70
|
+
|
71
|
+
context 'units option' do
|
72
|
+
it 'returns the current temperature in requested units' do
|
73
|
+
response = OpenWeather::Current.city('Cochin, In', units: 'metric')
|
74
|
+
temp_metric = response['main']['temp']
|
75
|
+
|
76
|
+
response = OpenWeather::Current.city('Cochin, In', units: 'imperial')
|
77
|
+
temp_imperial = response['main']['temp']
|
78
|
+
farenheit_to_celsius = ((temp_imperial - 32) / 1.8000)
|
79
|
+
|
80
|
+
expect(farenheit_to_celsius).to be_within(0.01).of(temp_metric)
|
81
|
+
end
|
82
|
+
end
|
78
83
|
end
|
79
84
|
|
80
85
|
describe 'Open weather Forecast API' do
|
@@ -113,4 +118,17 @@ describe 'Open weather Forecast API' do
|
|
113
118
|
response['cod'].to_s.should eq("404")
|
114
119
|
end
|
115
120
|
end
|
116
|
-
|
121
|
+
|
122
|
+
context 'units option' do
|
123
|
+
it 'returns the forecast in requested units' do
|
124
|
+
response = OpenWeather::Forecast.city('Cochin, In', units: 'metric')
|
125
|
+
temp_metric = response['list'].first['main']['temp']
|
126
|
+
|
127
|
+
response = OpenWeather::Forecast.city('Cochin, In', units: 'imperial')
|
128
|
+
temp_imperial = response['list'].first['main']['temp']
|
129
|
+
farenheit_to_celsius = ((temp_imperial - 32) / 1.8000)
|
130
|
+
|
131
|
+
expect(farenheit_to_celsius).to be_within(0.01).of(temp_metric)
|
132
|
+
end
|
133
|
+
end
|
134
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open-weather
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
4
|
+
version: 0.9.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-07-15 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rspec
|
@@ -29,23 +29,7 @@ dependencies:
|
|
29
29
|
- !ruby/object:Gem::Version
|
30
30
|
version: '0'
|
31
31
|
- !ruby/object:Gem::Dependency
|
32
|
-
name:
|
33
|
-
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
|
-
requirements:
|
36
|
-
- - ! '>='
|
37
|
-
- !ruby/object:Gem::Version
|
38
|
-
version: '0'
|
39
|
-
type: :runtime
|
40
|
-
prerelease: false
|
41
|
-
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
|
-
requirements:
|
44
|
-
- - ! '>='
|
45
|
-
- !ruby/object:Gem::Version
|
46
|
-
version: '0'
|
47
|
-
- !ruby/object:Gem::Dependency
|
48
|
-
name: addressable
|
32
|
+
name: json
|
49
33
|
requirement: !ruby/object:Gem::Requirement
|
50
34
|
none: false
|
51
35
|
requirements:
|