weather-api 1.0.1 → 1.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (75) hide show
  1. checksums.yaml +7 -0
  2. data/.travis.yml +1 -1
  3. data/Gemfile +1 -7
  4. data/README.md +3 -4
  5. data/Rakefile +1 -1
  6. data/lib/weather-api.rb +47 -25
  7. data/lib/weather-api/astronomy.rb +3 -3
  8. data/lib/weather-api/atmosphere.rb +4 -4
  9. data/lib/weather-api/condition.rb +5 -5
  10. data/lib/weather-api/forecast.rb +7 -7
  11. data/lib/weather-api/image.rb +2 -18
  12. data/lib/weather-api/location.rb +4 -4
  13. data/lib/weather-api/response.rb +14 -18
  14. data/lib/weather-api/units.rb +5 -5
  15. data/lib/weather-api/utils.rb +3 -3
  16. data/lib/weather-api/version.rb +2 -2
  17. data/lib/weather-api/wind.rb +4 -4
  18. data/spec/fixtures/cassettes/Weather_Astronomy/should_contain_Time_objects_for_sunrise_and_sunset.yml +62 -0
  19. data/spec/fixtures/cassettes/Weather_Atmosphere/should_contain_a_float_indicating_atmospheric_pressure.yml +62 -0
  20. data/spec/fixtures/cassettes/Weather_Atmosphere/should_contain_a_string_indicating_barometric_pressure.yml +62 -0
  21. data/spec/fixtures/cassettes/Weather_Atmosphere/should_contain_integers_representing_humidity_and_visibility.yml +62 -0
  22. data/spec/fixtures/cassettes/Weather_Condition/should_contain_a_weather_condition_code_a_date_a_temperature_and_a_description.yml +62 -0
  23. data/spec/fixtures/cassettes/Weather_Forecast/should_contain_high_and_low_forecasts.yml +62 -0
  24. data/spec/fixtures/cassettes/Weather_Forecast/should_contain_the_name_of_the_day_associated_with_the_forecast.yml +62 -0
  25. data/spec/fixtures/cassettes/Weather_Forecast/should_have_a_brief_description_of_the_forecasted_conditions.yml +62 -0
  26. data/spec/fixtures/cassettes/Weather_Forecast/should_have_a_weather_condition_code.yml +62 -0
  27. data/spec/fixtures/cassettes/Weather_Forecast/should_have_an_associated_date.yml +62 -0
  28. data/spec/fixtures/cassettes/Weather_Image/should_contain_a_string_for_the_image_url.yml +62 -0
  29. data/spec/fixtures/cassettes/Weather_Location/should_be_able_to_look_up_Nice_France.yml +62 -0
  30. data/spec/fixtures/cassettes/Weather_Location/should_be_able_to_look_up_Seattle_WA.yml +62 -0
  31. data/spec/fixtures/cassettes/Weather_Location/should_be_able_to_look_up_Victoria_BC.yml +62 -0
  32. data/spec/fixtures/cassettes/Weather_Location/should_contain_city_country_and_region_as_strings.yml +62 -0
  33. data/spec/fixtures/cassettes/Weather_Response/should_contain_a_HTML_description_summarizing_weather_conditions.yml +62 -0
  34. data/spec/fixtures/cassettes/Weather_Response/should_contain_a_String_title.yml +62 -0
  35. data/spec/fixtures/cassettes/Weather_Response/should_contain_a_Weather_Astronomy_object.yml +62 -0
  36. data/spec/fixtures/cassettes/Weather_Response/should_contain_a_Weather_Atmosphere_object.yml +62 -0
  37. data/spec/fixtures/cassettes/Weather_Response/should_contain_a_Weather_Condition_object.yml +62 -0
  38. data/spec/fixtures/cassettes/Weather_Response/should_contain_a_Weather_Image_object.yml +62 -0
  39. data/spec/fixtures/cassettes/Weather_Response/should_contain_a_Weather_Location_object.yml +62 -0
  40. data/spec/fixtures/cassettes/Weather_Response/should_contain_a_Weather_Units_object.yml +62 -0
  41. data/spec/fixtures/cassettes/Weather_Response/should_contain_a_Weather_Wind_object.yml +62 -0
  42. data/spec/fixtures/cassettes/Weather_Response/should_contain_a_collection_of_Weather_Forecast_objects.yml +62 -0
  43. data/spec/fixtures/cassettes/Weather_Response/should_contain_latitude_and_longitude_in_floats.yml +62 -0
  44. data/spec/fixtures/cassettes/Weather_Response/should_contain_the_WOEID_of_the_request_location_and_the_requested_URL.yml +62 -0
  45. data/spec/fixtures/cassettes/Weather_Units/defaults/should_default_to_imperial_units.yml +62 -0
  46. data/spec/fixtures/cassettes/Weather_Units/defaults/should_switch_to_metric_if_specified.yml +62 -0
  47. data/spec/fixtures/cassettes/Weather_Wind/should_contain_chill_direction_and_speed_as_integers.yml +62 -0
  48. data/spec/lib/astronomy_spec.rb +12 -0
  49. data/spec/lib/atmosphere_spec.rb +20 -0
  50. data/spec/lib/condition_spec.rb +14 -0
  51. data/spec/lib/forecast_spec.rb +28 -0
  52. data/spec/lib/image_spec.rb +11 -0
  53. data/spec/lib/location_spec.rb +36 -0
  54. data/spec/lib/response_spec.rb +57 -0
  55. data/spec/lib/units_spec.rb +30 -0
  56. data/spec/lib/utils_spec.rb +11 -0
  57. data/spec/lib/version_spec.rb +7 -0
  58. data/spec/lib/wind_spec.rb +13 -0
  59. data/spec/{helper.rb → spec_helper.rb} +3 -5
  60. data/weather-api.gemspec +9 -11
  61. metadata +127 -88
  62. data/Guardfile +0 -19
  63. data/lib/weather-api/api.rb +0 -33
  64. data/spec/cases/api_spec.rb +0 -8
  65. data/spec/cases/astronomy_spec.rb +0 -15
  66. data/spec/cases/atmosphere_spec.rb +0 -23
  67. data/spec/cases/condition_spec.rb +0 -17
  68. data/spec/cases/forecast_spec.rb +0 -32
  69. data/spec/cases/image_spec.rb +0 -21
  70. data/spec/cases/location_spec.rb +0 -41
  71. data/spec/cases/response_spec.rb +0 -60
  72. data/spec/cases/units_spec.rb +0 -36
  73. data/spec/cases/utils_spec.rb +0 -13
  74. data/spec/cases/version_spec.rb +0 -8
  75. data/spec/cases/wind_spec.rb +0 -16
data/Guardfile DELETED
@@ -1,19 +0,0 @@
1
- # A sample Guardfile
2
- # More info at https://github.com/guard/guard#readme
3
-
4
- guard 'rspec', :version => 2 do
5
- watch(%r{^spec/.+_spec\.rb$})
6
- watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
7
- watch('spec/spec_helper.rb') { "spec" }
8
-
9
- # Rails example
10
- watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
11
- watch(%r{^app/(.*)(\.erb|\.haml)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
12
- watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
13
- watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
14
- watch('config/routes.rb') { "spec/routing" }
15
- watch('app/controllers/application_controller.rb') { "spec/controllers" }
16
- # Capybara request specs
17
- watch(%r{^app/views/(.+)/.*\.(erb|haml)$}) { |m| "spec/requests/#{m[1]}_spec.rb" }
18
- end
19
-
@@ -1,33 +0,0 @@
1
- module Weather
2
- class API
3
- # Yahoo! Weather info endpoint
4
- ENDPOINT = "http://weather.yahooapis.com/forecastrss"
5
-
6
- # Public: Looks up current weather information using WOEID
7
- #
8
- # woeid - Int - Where On Earth IDentifier -- unique ID for
9
- # location to get weather data for. To find
10
- # a WOEID, refer to Yahoo!'s documentation
11
- # at http://developer.yahoo.com/weather/
12
- #
13
- # units - String - whether to retrieve data in Farenheit
14
- # or Celsius. Defaults to Farenheit
15
- #
16
- # Returns a Weather::Response object containing forecast
17
- def lookup(woeid, units = 'f')
18
- url = ENDPOINT + "?w=#{CGI.escape(woeid.to_s)}&u=#{CGI.escape(units.downcase)}"
19
-
20
- begin
21
- response = Net::HTTP.get_response(URI.parse(url)).body.to_s
22
- rescue => e
23
- raise RuntimeError.new("Failed to get weather [woeid=#{woeid}, url=#{url}, e=#{e}].")
24
- end
25
-
26
- # parse returned XML
27
- doc = Nokogiri::XML.parse(response)
28
-
29
- # create response object
30
- Weather::Response.new(woeid, url, doc)
31
- end
32
- end
33
- end
@@ -1,8 +0,0 @@
1
- require 'helper'
2
-
3
- describe Weather::API do
4
- it 'should alias Weather to Weather::API' do
5
- @api = Weather.new
6
- @api.should be_a Weather::API
7
- end
8
- end
@@ -1,15 +0,0 @@
1
- require 'helper'
2
-
3
- describe Weather::Astronomy do
4
- use_vcr_cassette
5
-
6
- before do
7
- @client = Weather::API.new
8
- @response = @client.lookup(9848)
9
- end
10
-
11
- it 'should contain Time objects for sunrise and sunset' do
12
- @response.astronomy.sunrise.should be_a Time
13
- @response.astronomy.sunset.should be_a Time
14
- end
15
- end
@@ -1,23 +0,0 @@
1
- require 'helper'
2
-
3
- describe Weather::Atmosphere do
4
- use_vcr_cassette
5
-
6
- before do
7
- @client = Weather::API.new
8
- @response = @client.lookup(9848)
9
- end
10
-
11
- it 'should contain a string indicating barometric pressure' do
12
- @response.atmosphere.barometer.should be_a String
13
- end
14
-
15
- it 'should contain integers representing humidity and visibility' do
16
- @response.atmosphere.humidity.should be_a Integer
17
- @response.atmosphere.visibility.should be_a Integer
18
- end
19
-
20
- it 'should contain a float indicating atmospheric pressure' do
21
- @response.atmosphere.pressure.should be_a Float
22
- end
23
- end
@@ -1,17 +0,0 @@
1
- require 'helper'
2
-
3
- describe Weather::Condition do
4
- use_vcr_cassette
5
-
6
- before do
7
- @client = Weather::API.new
8
- @response = @client.lookup(9848)
9
- end
10
-
11
- it 'should contain a weather condition code, a date, a temperature, and a description' do
12
- @response.condition.code.should be_a Integer
13
- @response.condition.date.should be_a Time
14
- @response.condition.temp.should be_a Integer
15
- @response.condition.text.should be_a String
16
- end
17
- end
@@ -1,32 +0,0 @@
1
- require 'helper'
2
-
3
- describe Weather::Forecast do
4
- use_vcr_cassette
5
-
6
- before do
7
- client = Weather::API.new
8
- response = client.lookup(9848)
9
- @forecast = response.forecasts[0]
10
- end
11
-
12
- it 'should have an associated date' do
13
- @forecast.date.should be_a Time
14
- end
15
-
16
- it 'should contain high and low forecasts' do
17
- @forecast.high.should be_a Integer
18
- @forecast.low.should be_a Integer
19
- end
20
-
21
- it 'should contain the name of the day associated with the forecast' do
22
- @forecast.day.should be_a String
23
- end
24
-
25
- it 'should have a weather condition code' do
26
- @forecast.code.should be_a Integer
27
- end
28
-
29
- it 'should have a brief description of the forecasted conditions' do
30
- @forecast.text.should be_a String
31
- end
32
- end
@@ -1,21 +0,0 @@
1
- require 'helper'
2
-
3
- describe Weather::Image do
4
- use_vcr_cassette
5
-
6
- before do
7
- @client = Weather::API.new
8
- @response = @client.lookup(9848)
9
- end
10
-
11
- it 'should contain integers for image height and width' do
12
- @response.image.height.should be_a Integer
13
- @response.image.width.should be_a Integer
14
- end
15
-
16
- it 'should contain strings for the image url, link, and title' do
17
- @response.image.url.should be_a String
18
- @response.image.link.should be_a String
19
- @response.image.title.should be_a String
20
- end
21
- end
@@ -1,41 +0,0 @@
1
- require 'helper'
2
-
3
- describe Weather::Location do
4
- use_vcr_cassette
5
-
6
- before do
7
- @client = Weather::API.new
8
- end
9
-
10
- it 'should contain city, country, and region as strings' do
11
- response = @client.lookup(9848)
12
-
13
- response.location.city.should be_a String
14
- response.location.region.should be_a String
15
- response.location.country.should be_a String
16
- end
17
-
18
- it 'should be able to look up Seattle, WA' do
19
- response = @client.lookup(2490383)
20
-
21
- response.location.city.should == 'Seattle'
22
- response.location.region.should == 'WA'
23
- response.location.country.should == 'United States'
24
- end
25
-
26
- it 'should be able to look up Victoria, BC' do
27
- response = @client.lookup(9848)
28
-
29
- response.location.city.should == 'Victoria'
30
- response.location.region.should == 'BC'
31
- response.location.country.should == 'Canada'
32
- end
33
-
34
- it 'should be able to look up Nice, France' do
35
- response = @client.lookup(614274)
36
-
37
- response.location.city.should == 'Nice'
38
- response.location.region.should == ''
39
- response.location.country.should == 'France'
40
- end
41
- end
@@ -1,60 +0,0 @@
1
- require 'helper'
2
-
3
- describe Weather::Response do
4
- use_vcr_cassette
5
-
6
- before do
7
- @client = Weather::API.new
8
- @response = @client.lookup(9848)
9
- end
10
-
11
- it 'should contain a Weather::Astronomy object' do
12
- @response.astronomy.should be_a Weather::Astronomy
13
- end
14
-
15
- it 'should contain a Weather::Location object' do
16
- @response.location.should be_a Weather::Location
17
- end
18
-
19
- it 'should contain a Weather::Units object' do
20
- @response.units.should be_a Weather::Units
21
- end
22
-
23
- it 'should contain a Weather::Wind object' do
24
- @response.wind.should be_a Weather::Wind
25
- end
26
-
27
- it 'should contain a Weather::Atmosphere object' do
28
- @response.atmosphere.should be_a Weather::Atmosphere
29
- end
30
-
31
- it 'should contain a Weather::Condition object' do
32
- @response.condition.should be_a Weather::Condition
33
- end
34
-
35
- it 'should contain a collection of Weather::Forecast objects' do
36
- @response.forecasts[0].should be_a Weather::Forecast
37
- end
38
-
39
- it 'should contain a Weather::Image object' do
40
- @response.image.should be_a Weather::Image
41
- end
42
-
43
- it 'should contain the WOEID of the request location and the requested URL' do
44
- @response.request_location.should == 9848
45
- @response.request_url.should == "http://weather.yahooapis.com/forecastrss?w=9848&u=f"
46
- end
47
-
48
- it 'should contain a HTML description summarizing weather conditions' do
49
- @response.description.should be_a String
50
- end
51
-
52
- it 'should contain a String title' do
53
- @response.title.should be_a String
54
- end
55
-
56
- it 'should contain latitude and longitude in floats' do
57
- @response.latitude.should be_a Float
58
- @response.longitude.should be_a Float
59
- end
60
- end
@@ -1,36 +0,0 @@
1
- require 'helper'
2
-
3
- describe Weather::Units do
4
- before do
5
- @client = Weather::API.new
6
- end
7
-
8
- describe 'constants' do
9
- it 'should have constants for celsius and farenheit' do
10
- Weather::Units::FARENHEIT.should == 'f'
11
- Weather::Units::CELSIUS.should == 'c'
12
- end
13
- end
14
-
15
- describe 'defaults' do
16
- use_vcr_cassette
17
-
18
- it 'should default to imperial units' do
19
- response = @client.lookup(9848)
20
-
21
- response.units.distance.should == 'mi'
22
- response.units.pressure.should == 'in'
23
- response.units.speed.should == 'mph'
24
- response.units.temperature.should == 'F'
25
- end
26
-
27
- it 'should switch to metric if specified' do
28
- response = @client.lookup(9848, 'c')
29
-
30
- response.units.distance.should == 'km'
31
- response.units.pressure.should == 'mb'
32
- response.units.speed.should == 'km/h'
33
- response.units.temperature.should == 'C'
34
- end
35
- end
36
- end
@@ -1,13 +0,0 @@
1
- require 'helper'
2
-
3
- describe Weather::Utils do
4
- it 'should parse text into a Time object' do
5
- time = Weather::Utils.parse_time('2007-01-31 12:22:26')
6
- time.should be_a Time
7
- end
8
-
9
- it 'should return nil if passed nothing' do
10
- time = Weather::Utils.parse_time('')
11
- time.should == nil
12
- end
13
- end
@@ -1,8 +0,0 @@
1
- require "helper"
2
-
3
- describe Weather::Version do
4
- it "should return a string" do
5
- string = Weather::Version.to_s
6
- string.should be_a String
7
- end
8
- end
@@ -1,16 +0,0 @@
1
- require 'helper'
2
-
3
- describe Weather::Wind do
4
- use_vcr_cassette
5
-
6
- before do
7
- @client = Weather::API.new
8
- @response = @client.lookup(9848)
9
- end
10
-
11
- it 'should contain chill, direction, and speed as integers' do
12
- @response.wind.chill.should be_a Integer
13
- @response.wind.direction.should be_a Integer
14
- @response.wind.speed.should be_a Integer
15
- end
16
- end