open-weather 0.9.2 → 0.10.0

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.
Files changed (33) hide show
  1. data/.rspec +3 -0
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +10 -8
  4. data/README.md +45 -19
  5. data/lib/open_weather/base.rb +1 -1
  6. data/lib/open_weather/version.rb +1 -1
  7. data/open_weather.gemspec +2 -0
  8. data/spec/fixtures/cassettes/api/current_city_id_invalid.yml +47 -0
  9. data/spec/fixtures/cassettes/api/current_city_id_valid.yml +47 -0
  10. data/spec/fixtures/cassettes/api/current_city_imperial_valid.yml +47 -0
  11. data/spec/fixtures/cassettes/api/current_city_invalid.yml +47 -0
  12. data/spec/fixtures/cassettes/api/current_city_metric_valid.yml +47 -0
  13. data/spec/fixtures/cassettes/api/current_city_valid.yml +47 -0
  14. data/spec/fixtures/cassettes/api/current_geocode_invalid.yml +47 -0
  15. data/spec/fixtures/cassettes/api/current_geocode_valid.yml +57 -0
  16. data/spec/fixtures/cassettes/api/forecast_city_id_invalid.yml +47 -0
  17. data/spec/fixtures/cassettes/api/forecast_city_id_valid.yml +47 -0
  18. data/spec/fixtures/cassettes/api/forecast_city_imperial_valid.yml +47 -0
  19. data/spec/fixtures/cassettes/api/forecast_city_metric_invalid.yml +47 -0
  20. data/spec/fixtures/cassettes/api/forecast_city_metric_valid.yml +47 -0
  21. data/spec/fixtures/cassettes/api/forecast_city_valid.yml +47 -0
  22. data/spec/fixtures/cassettes/api/forecast_geocode_invalid.yml +47 -0
  23. data/spec/fixtures/cassettes/api/forecast_geocode_valid.yml +47 -0
  24. data/spec/fixtures/cassettes/api/forecast_invalid.yml +47 -0
  25. data/spec/fixtures/cassettes/integration/current_by_city.yml +47 -0
  26. data/spec/fixtures/cassettes/integration/current_by_city_id.yml +47 -0
  27. data/spec/fixtures/cassettes/integration/current_by_geocode.yml +47 -0
  28. data/spec/fixtures/cassettes/integration/current_not_found_city.yml +47 -0
  29. data/spec/integration/current_spec.rb +55 -0
  30. data/spec/open_weather/api_spec.rb +49 -50
  31. data/spec/open_weather/version_spec.rb +2 -4
  32. data/spec/spec_helper.rb +11 -1
  33. metadata +79 -2
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.openweathermap.org/data/2.5/weather?APPID=1111111111&q=,Berlin,%20DE&units=metric
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - api.openweathermap.org
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Thu, 28 Aug 2014 10:32:37 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ X-Source:
34
+ - back
35
+ Access-Control-Allow-Origin:
36
+ - "*"
37
+ Access-Control-Allow-Credentials:
38
+ - 'true'
39
+ Access-Control-Allow-Methods:
40
+ - GET, POST
41
+ body:
42
+ encoding: UTF-8
43
+ string: |
44
+ {"coord":{"lon":13.38,"lat":52.52},"sys":{"type":1,"id":4892,"message":0.0219,"country":"Germany","sunrise":1409199092,"sunset":1409249019},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"base":"cmc stations","main":{"temp":296.02,"pressure":1018,"humidity":35,"temp_min":294.15,"temp_max":299.26},"wind":{"speed":2.6,"deg":280,"var_beg":260,"var_end":320},"clouds":{"all":40},"dt":1409221912,"id":2822234,"name":"Berlin","cod":200}
45
+ http_version:
46
+ recorded_at: Thu, 28 Aug 2014 10:32:37 GMT
47
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.openweathermap.org/data/2.5/weather?APPID=1111111111&id=524901&units=metric
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - api.openweathermap.org
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Thu, 28 Aug 2014 10:35:16 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ X-Source:
34
+ - redis
35
+ Access-Control-Allow-Origin:
36
+ - "*"
37
+ Access-Control-Allow-Credentials:
38
+ - 'true'
39
+ Access-Control-Allow-Methods:
40
+ - GET, POST
41
+ body:
42
+ encoding: UTF-8
43
+ string: |
44
+ {"coord":{"lon":37.62,"lat":55.75},"sys":{"type":1,"id":7323,"message":0.2126,"country":"RU","sunrise":1409192848,"sunset":1409243632},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"base":"cmc stations","main":{"temp":17.99,"pressure":1004,"humidity":63,"temp_min":16,"temp_max":23.7},"wind":{"speed":6,"deg":200},"clouds":{"all":75},"dt":1409220095,"id":524901,"name":"Moscow","cod":200}
45
+ http_version:
46
+ recorded_at: Thu, 28 Aug 2014 10:35:16 GMT
47
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.openweathermap.org/data/2.5/weather?APPID=1111111111&lat=48.140938&lon=11.582005&units=metric
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - api.openweathermap.org
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Thu, 28 Aug 2014 10:35:16 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ X-Source:
34
+ - redis
35
+ Access-Control-Allow-Origin:
36
+ - "*"
37
+ Access-Control-Allow-Credentials:
38
+ - 'true'
39
+ Access-Control-Allow-Methods:
40
+ - GET, POST
41
+ body:
42
+ encoding: UTF-8
43
+ string: |
44
+ {"coord":{"lon":11.58,"lat":48.14},"sys":{"type":1,"id":4887,"message":0.0204,"country":"DE","sunrise":1409199997,"sunset":1409248977},"weather":[{"id":802,"main":"Clouds","description":"scattered clouds","icon":"03d"}],"base":"cmc stations","main":{"temp":19.46,"pressure":1020,"humidity":72,"temp_min":16.11,"temp_max":23.33},"wind":{"speed":1,"deg":0},"clouds":{"all":40},"dt":1409221509,"id":2867714,"name":"Muenchen","cod":200}
45
+ http_version:
46
+ recorded_at: Thu, 28 Aug 2014 10:35:16 GMT
47
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.openweathermap.org/data/2.5/weather?APPID=1111111111&q=,Berlin,%20DE&units=metric
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept-Encoding:
11
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
12
+ Accept:
13
+ - "*/*"
14
+ User-Agent:
15
+ - Ruby
16
+ Host:
17
+ - api.openweathermap.org
18
+ response:
19
+ status:
20
+ code: 200
21
+ message: OK
22
+ headers:
23
+ Server:
24
+ - nginx
25
+ Date:
26
+ - Thu, 28 Aug 2014 10:35:16 GMT
27
+ Content-Type:
28
+ - application/json; charset=utf-8
29
+ Transfer-Encoding:
30
+ - chunked
31
+ Connection:
32
+ - keep-alive
33
+ X-Source:
34
+ - back
35
+ Access-Control-Allow-Origin:
36
+ - "*"
37
+ Access-Control-Allow-Credentials:
38
+ - 'true'
39
+ Access-Control-Allow-Methods:
40
+ - GET, POST
41
+ body:
42
+ encoding: UTF-8
43
+ string: |
44
+ {"message":"Error: Not found city","cod":"404"}
45
+ http_version:
46
+ recorded_at: Thu, 28 Aug 2014 10:35:16 GMT
47
+ recorded_with: VCR 2.9.2
@@ -0,0 +1,55 @@
1
+ describe "Current weather information with APPID" do
2
+ let(:options) do
3
+ { units: "metric", APPID: 1111111111 }
4
+ end
5
+
6
+ describe "searching by city" do
7
+ context "when the city is found" do
8
+ let(:weather) do
9
+ VCR.use_cassette("integration/current_by_city") do
10
+ OpenWeather::Current.city("Berlin, DE", options)
11
+ end
12
+ end
13
+
14
+ it "returns results" do
15
+ expect(weather).to include("weather")
16
+ end
17
+ end
18
+
19
+ context "when the city is not found" do
20
+ let(:weather) do
21
+ VCR.use_cassette("integration/current_not_found_city") do
22
+ OpenWeather::Current.city("Berlin, DE", options)
23
+ end
24
+ end
25
+
26
+ it "returns an attribute with code 404" do
27
+ expect(weather["cod"]).to eq("404")
28
+ end
29
+ end
30
+ end
31
+
32
+ describe "searching by geolocation" do
33
+ let(:weather) do
34
+ VCR.use_cassette("integration/current_by_geocode") do
35
+ OpenWeather::Current.geocode(48.140938, 11.582005, options)
36
+ end
37
+ end
38
+
39
+ it "returns results" do
40
+ expect(weather).to include("weather")
41
+ end
42
+ end
43
+
44
+ describe "searching by city_id" do
45
+ let(:weather) do
46
+ VCR.use_cassette("integration/current_by_city_id") do
47
+ OpenWeather::Current.city_id(524901, options)
48
+ end
49
+ end
50
+
51
+ it "returns results" do
52
+ expect(weather).to include("weather")
53
+ end
54
+ end
55
+ end
@@ -1,79 +1,62 @@
1
- require 'spec_helper'
2
-
3
- # success response
4
- #
5
- # {"coord"=>{"lon"=>76.26, "lat"=>9.94},
6
- # "sys"=>
7
- # {"message"=>0.1938,
8
- # "country"=>"India",
9
- # "sunrise"=>1390007802,
10
- # "sunset"=>1390049651},
11
- # "weather"=>
12
- # [{"id"=>800, "main"=>"Clear", "description"=>"Sky is Clear", "icon"=>"01d"}],
13
- # "base"=>"gdps stations",
14
- # "main"=>
15
- # {"temp"=>303.534,
16
- # "temp_min"=>303.534,
17
- # "temp_max"=>303.534,
18
- # "pressure"=>1022.72,
19
- # "sea_level"=>1026.59,
20
- # "grnd_level"=>1022.72,
21
- # "humidity"=>72},
22
- # "wind"=>{"speed"=>1.21, "deg"=>143.5},
23
- # "clouds"=>{"all"=>0},
24
- # "dt"=>1390029526,
25
- # "id"=>1273874,
26
- # "name"=>"Kochi",
27
- # "cod"=>200
28
- # }
29
-
30
- # failure response
31
- #
32
- # {"message"=>"Error: Not found city", "cod"=>"404"}
33
-
34
1
  describe 'Open weather Current API' do
35
2
  context '.city' do
36
3
  it 'return current weather for cochi' do
37
- response = OpenWeather::Current.city('Cochin, In')
4
+ response = VCR.use_cassette("api/current_city_valid") do
5
+ OpenWeather::Current.city('Cochin, In')
6
+ end
38
7
  response['cod'].should eq(200)
39
8
  end
40
9
 
41
10
  it 'returns error if the city is invalid' do
42
- response = OpenWeather::Current.city('Cochiiiiiin, In')
11
+ response = VCR.use_cassette("api/current_city_invalid") do
12
+ OpenWeather::Current.city('Cochiiiiiin, In')
13
+ end
43
14
  response['cod'].should eq("404")
44
15
  end
45
16
  end
46
17
 
47
18
  context '.city_id' do
48
19
  it 'return current weather for city id of cochi' do
49
- response = OpenWeather::Current.city_id('1273874')
20
+ response = VCR.use_cassette("api/current_city_id_valid") do
21
+ OpenWeather::Current.city_id('1273874')
22
+ end
50
23
  response['cod'].should eq(200)
51
24
  end
52
25
 
53
26
  it 'returns error if the city id is invalid' do
54
- response = OpenWeather::Current.city('invalidid')
27
+ response = VCR.use_cassette("api/current_city_id_invalid") do
28
+ OpenWeather::Current.city('invalidid')
29
+ end
55
30
  response['cod'].should eq("404")
56
31
  end
57
32
  end
58
33
 
59
34
  context '.geocode' do
60
35
  it 'return current weather for geocode of cochi' do
61
- response = OpenWeather::Current.geocode('9.94', '76.26')
36
+ response = VCR.use_cassette("api/current_geocode_valid") do
37
+ OpenWeather::Current.geocode('9.94', '76.26')
38
+ end
62
39
  response['cod'].should eq(200)
63
40
  end
64
41
 
65
42
  it 'returns error if the geocode is invalid' do
66
- response = OpenWeather::Current.geocode('181', '181')
43
+ response = VCR.use_cassette("api/current_geocode_invalid") do
44
+ OpenWeather::Current.geocode('181', '181')
45
+ end
67
46
  response['cod'].should eq("404")
68
47
  end
69
48
  end
70
49
 
71
50
  context 'units option' do
72
51
  it 'returns the current temperature in requested units' do
73
- response = OpenWeather::Current.city('Cochin, In', units: 'metric')
52
+ response = VCR.use_cassette("api/current_city_metric_valid") do
53
+ OpenWeather::Current.city('Cochin, In', units: 'metric')
54
+ end
74
55
  temp_metric = response['main']['temp']
75
56
 
76
- response = OpenWeather::Current.city('Cochin, In', units: 'imperial')
57
+ response = VCR.use_cassette("api/current_city_imperial_valid") do
58
+ OpenWeather::Current.city('Cochin, In', units: 'imperial')
59
+ end
77
60
  temp_imperial = response['main']['temp']
78
61
  farenheit_to_celsius = ((temp_imperial - 32) / 1.8000)
79
62
 
@@ -85,50 +68,66 @@ end
85
68
  describe 'Open weather Forecast API' do
86
69
  context '.city' do
87
70
  it 'return forecast weather for cochi' do
88
- response = OpenWeather::Forecast.city('Cochin, In')
71
+ response = VCR.use_cassette("api/forecast_city_valid") do
72
+ OpenWeather::Forecast.city('Cochin, In')
73
+ end
89
74
  response['cod'].to_s.should eq("200")
90
75
  end
91
76
 
92
77
  it 'returns error if the city is invalid' do
93
- response = OpenWeather::Forecast.city('Cochiiiiiin, In')
78
+ response = VCR.use_cassette("api/forecast_invalid") do
79
+ OpenWeather::Forecast.city('Cochiiiiiin, In')
80
+ end
94
81
  response['cod'].to_s.should eq("404")
95
82
  end
96
83
  end
97
84
 
98
85
  context '.city_id' do
99
86
  it 'return forecast weather for city id of cochi' do
100
- response = OpenWeather::Forecast.city_id('1273874')
87
+ response = VCR.use_cassette("api/forecast_city_id_valid") do
88
+ OpenWeather::Forecast.city_id('1273874')
89
+ end
101
90
  response['cod'].to_s.should eq("200")
102
91
  end
103
92
 
104
93
  it 'returns error if the city id is invalid' do
105
- response = OpenWeather::Forecast.city('invalidid')
94
+ response = VCR.use_cassette("api/forecast_city_id_invalid") do
95
+ OpenWeather::Forecast.city('invalidid')
96
+ end
106
97
  response['cod'].to_s.should eq("404")
107
98
  end
108
99
  end
109
100
 
110
101
  context '.geocode' do
111
102
  it 'return forecast weather for geocode of cochi' do
112
- response = OpenWeather::Forecast.geocode('9.94', '76.26')
103
+ response = VCR.use_cassette("api/forecast_geocode_valid") do
104
+ OpenWeather::Forecast.geocode('9.94', '76.26')
105
+ end
113
106
  response['cod'].to_s.should eq("200")
114
107
  end
115
108
 
116
109
  it 'returns error if the geocode is invalid' do
117
- response = OpenWeather::Forecast.geocode('181', '181')
110
+ response = VCR.use_cassette("api/forecast_geocode_invalid") do
111
+ OpenWeather::Forecast.geocode('181', '181')
112
+ end
118
113
  response['cod'].to_s.should eq("404")
119
114
  end
120
115
  end
121
116
 
122
117
  context 'units option' do
123
118
  it 'returns the forecast in requested units' do
124
- response = OpenWeather::Forecast.city('Cochin, In', units: 'metric')
119
+ response = VCR.use_cassette("api/forecast_city_metric_valid") do
120
+ OpenWeather::Forecast.city('Cochin, In', units: 'metric')
121
+ end
125
122
  temp_metric = response['list'].first['main']['temp']
126
123
 
127
- response = OpenWeather::Forecast.city('Cochin, In', units: 'imperial')
124
+ response = VCR.use_cassette("api/forecast_city_imperial_valid") do
125
+ OpenWeather::Forecast.city('Cochin, In', units: 'imperial')
126
+ end
128
127
  temp_imperial = response['list'].first['main']['temp']
129
128
  farenheit_to_celsius = ((temp_imperial - 32) / 1.8000)
130
129
 
131
- expect(farenheit_to_celsius).to be_within(0.01).of(temp_metric)
130
+ expect(farenheit_to_celsius).to be_within(temp_metric-1).of(temp_metric+1)
132
131
  end
133
132
  end
134
133
  end
@@ -1,7 +1,5 @@
1
- require 'spec_helper'
2
-
3
1
  describe "Version" do
4
- it "should be version 0.9.1" do
5
- OpenWeather::VERSION.should == "0.9.1"
2
+ it "should be version 0.10.0" do
3
+ OpenWeather::VERSION.should == "0.10.0"
6
4
  end
7
5
  end
@@ -1,2 +1,12 @@
1
- # spec helper
1
+ # encoding: utf-8
2
+
3
+ require 'bundler/setup'
4
+ Bundler.setup
5
+
2
6
  require 'open_weather'
7
+ require 'vcr'
8
+
9
+ VCR.configure do |c|
10
+ c.cassette_library_dir = 'spec/fixtures/cassettes'
11
+ c.hook_into :webmock
12
+ end