open-weather 0.9.2 → 0.10.0

Sign up to get free protection for your applications and to get access to all the features.
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
data/.rspec ADDED
@@ -0,0 +1,3 @@
1
+ --color
2
+ --require spec_helper
3
+ --format documentation
data/Gemfile CHANGED
@@ -1,5 +1,5 @@
1
1
  source 'http://rubygems.org'
2
2
 
3
- gem 'httparty'
4
- gem 'addressable'
5
3
  gem 'rspec'
4
+ gem 'vcr'
5
+ gem 'webmock'
@@ -1,13 +1,10 @@
1
1
  GEM
2
2
  remote: http://rubygems.org/
3
3
  specs:
4
- addressable (2.3.4)
4
+ addressable (2.3.6)
5
+ crack (0.4.2)
6
+ safe_yaml (~> 1.0.0)
5
7
  diff-lcs (1.2.2)
6
- httparty (0.11.0)
7
- multi_json (~> 1.0)
8
- multi_xml (>= 0.5.2)
9
- multi_json (1.7.3)
10
- multi_xml (0.5.3)
11
8
  rspec (2.13.0)
12
9
  rspec-core (~> 2.13.0)
13
10
  rspec-expectations (~> 2.13.0)
@@ -16,11 +13,16 @@ GEM
16
13
  rspec-expectations (2.13.0)
17
14
  diff-lcs (>= 1.1.3, < 2.0)
18
15
  rspec-mocks (2.13.0)
16
+ safe_yaml (1.0.3)
17
+ vcr (2.9.2)
18
+ webmock (1.18.0)
19
+ addressable (>= 2.3.6)
20
+ crack (>= 0.3.2)
19
21
 
20
22
  PLATFORMS
21
23
  ruby
22
24
 
23
25
  DEPENDENCIES
24
- addressable
25
- httparty
26
26
  rspec
27
+ vcr
28
+ webmock
data/README.md CHANGED
@@ -12,35 +12,61 @@ Add the following to your **Gemfile**
12
12
 
13
13
  ## Usage
14
14
 
15
- require 'open_weather'
16
15
 
17
- # current weather APIs
16
+ ### Current weather information API
18
17
 
19
- # get current weather by city name
20
- OpenWeather::Current.city("Cochin, IN")
18
+ ```ruby
19
+ require 'open_weather'
21
20
 
22
- # get current weather by city id
23
- OpenWeather::Current.city_id("1273874")
21
+ # get current weather by city name
22
+ OpenWeather::Current.city("Cochin, IN")
24
23
 
25
- # get current weather by geocode. (lat, lon)
26
- OpenWeather::Current.geocode(9.94, 76.26)
24
+ # get current weather by city id
25
+ OpenWeather::Current.city_id("1273874")
27
26
 
28
- # get the current weather in degrees celsius
29
- OpenWeather::Current.city("Cochin, IN", units: 'metric')
27
+ # get current weather by geocode. (lat, lon)
28
+ OpenWeather::Current.geocode(9.94, 76.26)
30
29
 
31
- # weather forecast APIs
30
+ # get the current weather in degrees celsius
31
+ OpenWeather::Current.city("Cochin, IN", units: 'metric')
32
+ ```
32
33
 
33
- # get weather forecast by city name
34
- OpenWeather::Forecast.city("Cochin, IN")
34
+ Documentation about the current weather end-point:
35
+ http://openweathermap.org/current
35
36
 
36
- # get weather forecast by city name in fahrenheit
37
- OpenWeather::Forecast.city("Cochin, IN", units: 'imperial')
38
37
 
39
- # get weather forecast by city id
40
- OpenWeather::Forecast.city_id("1273874")
38
+ ### Weather forecast API
39
+
40
+ ```ruby
41
+ require 'open_weather'
42
+
43
+ # get weather forecast by city name
44
+ OpenWeather::Forecast.city("Cochin, IN")
45
+
46
+ # get weather forecast by city name in fahrenheit
47
+ OpenWeather::Forecast.city("Cochin, IN", units: 'imperial')
48
+
49
+ # get weather forecast by city id
50
+ OpenWeather::Forecast.city_id("1273874")
51
+
52
+ # get weather forecast by geocode. (lat, lon)
53
+ OpenWeather::Forecast.geocode(9.94, 76.26)
54
+ ```
55
+
56
+ Doucumentation about the weather forecast end-point:
57
+ http://openweathermap.org/forecast
58
+
59
+ #### Using the API key
60
+
61
+ ```ruby
62
+ # get current weather by city name
63
+ options = { units: "metric", APPID: 1111111111 }
64
+ OpenWeather::Current.city("Berlin, DE", options)
65
+ ```
66
+
67
+ How to get an API key and tips for an effective usage of the API:
68
+ http://openweathermap.org/appid
41
69
 
42
- # get weather forecast by geocode. (lat, lon)
43
- OpenWeather::Forecast.geocode(9.94, 76.26)
44
70
 
45
71
  ## Contributing
46
72
 
@@ -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, :units]
27
+ valid_options = [:lat, :lon, :city, :country, :id, :units, :APPID]
28
28
  options.keys.each { |k| options.delete(k) unless valid_options.include?(k) }
29
29
 
30
30
  if options[:city] || options[:country]
@@ -1,3 +1,3 @@
1
1
  module OpenWeather
2
- VERSION = "0.9.2"
2
+ VERSION = "0.10.0"
3
3
  end
@@ -14,5 +14,7 @@ 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
+ gem.add_development_dependency "vcr"
18
+ gem.add_development_dependency "webmock"
17
19
  gem.add_runtime_dependency 'json'
18
20
  end
@@ -0,0 +1,47 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: http://api.openweathermap.org/data/2.5/weather?q=,invalidid
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:50:49 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:50:48 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?id=1273874
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:50:49 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":76.26,"lat":9.94},"sys":{"message":0.8839,"country":"IN","sunrise":1409186753,"sunset":1409231181},"weather":[{"id":803,"main":"Clouds","description":"broken clouds","icon":"04d"}],"base":"cmc stations","main":{"temp":299.941,"temp_min":299.941,"temp_max":299.941,"pressure":1021.68,"sea_level":1023.32,"grnd_level":1021.68,"humidity":100},"wind":{"speed":4.91,"deg":311.006},"clouds":{"all":64},"dt":1409221397,"id":1273874,"name":"Cochin","cod":200}
45
+ http_version:
46
+ recorded_at: Thu, 28 Aug 2014 10:50:48 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?q=,Cochin,%20In&units=imperial
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:52:09 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":76.26,"lat":9.94},"sys":{"message":0.0316,"country":"India","sunrise":1409186752,"sunset":1409231181},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"base":"cmc stations","main":{"temp":79.96,"temp_min":79.96,"temp_max":79.96,"pressure":1020.95,"sea_level":1021.19,"grnd_level":1020.95,"humidity":99},"wind":{"speed":11.79,"deg":313.001},"clouds":{"all":88},"dt":1409222765,"id":1273874,"name":"Kochi","cod":200}
45
+ http_version:
46
+ recorded_at: Thu, 28 Aug 2014 10:52:09 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?q=,Cochiiiiiin,%20In
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:50:49 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:50:48 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?q=,Cochin,%20In&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:50:49 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":76.26,"lat":9.94},"sys":{"message":0.0191,"country":"India","sunrise":1409186752,"sunset":1409231181},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"base":"cmc stations","main":{"temp":26.643,"temp_min":26.643,"temp_max":26.643,"pressure":1020.95,"sea_level":1021.19,"grnd_level":1020.95,"humidity":99},"wind":{"speed":5.46,"deg":313.001},"clouds":{"all":88},"dt":1409222627,"id":1273874,"name":"Kochi","cod":200}
45
+ http_version:
46
+ recorded_at: Thu, 28 Aug 2014 10:50:49 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?q=,Cochin,%20In
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:50:48 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":76.26,"lat":9.94},"sys":{"message":0.0191,"country":"India","sunrise":1409186752,"sunset":1409231181},"weather":[{"id":804,"main":"Clouds","description":"overcast clouds","icon":"04d"}],"base":"cmc stations","main":{"temp":299.793,"temp_min":299.793,"temp_max":299.793,"pressure":1020.95,"sea_level":1021.19,"grnd_level":1020.95,"humidity":99},"wind":{"speed":5.46,"deg":313.001},"clouds":{"all":88},"dt":1409222627,"id":1273874,"name":"Kochi","cod":200}
45
+ http_version:
46
+ recorded_at: Thu, 28 Aug 2014 10:50:48 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?lat=181&lon=181
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:50:49 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:50:48 GMT
47
+ recorded_with: VCR 2.9.2