accuweather 0.1.3 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: bc7bfc4757609cb611775de025b9612c43913cbd
4
- data.tar.gz: 630af49fdd6319f9016b1ae43955e979f19d1d34
3
+ metadata.gz: 124f2a15ba49358b7e5295744cfcd0e57f2966c7
4
+ data.tar.gz: c1d023b93d04c8d304eb88307118dc1b9350ba69
5
5
  SHA512:
6
- metadata.gz: e7b5678dc93483e02ad3cc0f4b73ddeeff09266f43888ad663583684a9b21b5f2b6e6d7a7dc9eb24b3511f1f9d2a2626a7126efa54a934ee212a4664e4b305cf
7
- data.tar.gz: d74ea8bf168345691bffeea22b9171911d3f180bf63f0b75603776c1f8afd881bdd25f4a9cbbd1930ef07f95a86eba795c79b0ba361cffcab421646d6c93b030
6
+ metadata.gz: 0580cc1e46e4e32bdca467d0cc04aa562c2828e3ec6d0f619ad410755b4180b8ceeb57166b2a87c71f3320a75bd523503a27d5b7a4dc141f57e373980f5e1506
7
+ data.tar.gz: d30676ac42391f4f43d91ca24c90e50c883c37f63dbec17860d0d08087c32da3d92cf83522233e3ee82923540a40085bc388163681ea39dc360bdae466d3dc44
data/README.md CHANGED
@@ -45,6 +45,26 @@ current_weather.humidity # => '43%'
45
45
  current_weather.cloud_cover # => '40%'
46
46
  ```
47
47
 
48
+ Get forecast details:
49
+
50
+ ```ruby
51
+ weather_forecast = Accuweather.get_conditions(location_id: 'cityId:53286').forecast
52
+ last_forecast_day = weather_forecast.last
53
+ last_forecast_day.date # => "12/3/2015"
54
+ last_forecast_day.day_of_week # => "Thursday"
55
+ last_forecast_day.sunrise # => "7:49 AM"
56
+ last_forecast_day.sunset # => "4:16 PM"
57
+
58
+ # Get the dates, daytime high and nighttime low temperatures
59
+ weather_forecast.map(&:date) # => ["11/27/2015", "11/28/2015", "11/29/2015", "11/30/2015", "12/1/2015", "12/2/2015", "12/3/2015"]
60
+ weather_forecast.map(&:daytime).map(&:high_temperature) # => ["45", "45", "47", "44", "44", "48", "48"]
61
+ weather_forecast.map(&:nighttime).map(&:low_temperature) # => ["27", "28", "31", "32", "40", "42", "36"]
62
+ ```
63
+
64
+ Here is a full list of attributes for daytime and nighttime forecasts:
65
+
66
+ `weather_text`,`weather_text_long`,`weather_icon`,`high_temperature`,`low_temperature`,`real_feel_high`,`real_feel_low`,`wind_speed`,`wind_direction`,`wind_gust`,`max_uv`,`rain_amount`,`snow_amount`,`ice_amount`,`precipitation_amount`,`thunderstorm_probability`,`rain_probability`,`snow_probability`,`ice_probability` and `precipitation_probability`
67
+
48
68
  Get the units for the conditions:
49
69
 
50
70
  ```ruby
@@ -9,9 +9,8 @@ Gem::Specification.new do |spec|
9
9
  spec.authors = ['Nick Aschenbach']
10
10
  spec.email = ['nick.aschenbach@gmail.com']
11
11
 
12
- spec.summary = 'Access current weather report for cities around the world'
13
- spec.description = 'A simple web API wrapper to get weather information for cities around the world using the accuweather API. Includes
14
- temperature, pressure, humidity, weather text and GPS coordinates.'
12
+ spec.summary = 'Access current and future weather reports for cities around the world'
13
+ spec.description = 'Get weather information for cities around the world using the accuweather web API. Includes current current conditions for temperature, pressure and humidity. Forecasts include temperature highs, lows, "real feels", UV, wind speed, rain, snow, ice probabilities and amounts.'
15
14
  spec.homepage = 'https://github.com/nick-aschenbach/accuweather'
16
15
 
17
16
  spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
@@ -19,7 +18,7 @@ temperature, pressure, humidity, weather text and GPS coordinates.'
19
18
 
20
19
  spec.add_development_dependency 'bundler', '~> 1.10'
21
20
  spec.add_development_dependency 'rake', '~> 10.0'
22
- spec.add_development_dependency 'rspec'
21
+ spec.add_development_dependency 'rspec', '~> 3.4'
23
22
 
24
23
  spec.add_runtime_dependency 'nokogiri'
25
24
  end
@@ -5,6 +5,8 @@ require 'accuweather/conditions/parser'
5
5
  require 'accuweather/conditions/units'
6
6
  require 'accuweather/conditions/local'
7
7
  require 'accuweather/conditions/current'
8
+ require 'accuweather/conditions/forecast_day'
9
+ require 'accuweather/conditions/forecast_weather'
8
10
 
9
11
  require 'net/http'
10
12
  require 'nokogiri'
@@ -1,10 +1,9 @@
1
1
  module Accuweather
2
2
  module Conditions
3
3
  class Current
4
- attr_reader :url, :observation_time, :pressure, :temperature, :real_feel, :humidity, :weather_text, :weather_icon, :wind_gusts, :wind_speed, :wind_direction, :visibility, :precip, :uv_index, :dewpoint, :cloud_cover
4
+ attr_reader :observation_time, :pressure, :temperature, :real_feel, :humidity, :weather_text, :weather_icon, :wind_gusts, :wind_speed, :wind_direction, :visibility, :precipitation, :uv_index, :dewpoint, :cloud_cover
5
5
 
6
- def initialize(url:, observation_time:, pressure:, temperature:, real_feel:, humidity:, weather_text:, weather_icon:, wind_gusts:, wind_speed:, wind_direction:, visibility:, precip:, uv_index:, dewpoint:, cloud_cover:)
7
- @url = url
6
+ def initialize(observation_time:, pressure:, temperature:, real_feel:, humidity:, weather_text:, weather_icon:, wind_gusts:, wind_speed:, wind_direction:, visibility:, precipitation:, uv_index:, dewpoint:, cloud_cover:)
8
7
  @observation_time = observation_time
9
8
  @pressure = pressure
10
9
  @temperature = temperature
@@ -16,35 +15,34 @@ module Accuweather
16
15
  @wind_speed = wind_speed
17
16
  @wind_direction = wind_direction
18
17
  @visibility = visibility
19
- @precip = precip
18
+ @precipitation = precipitation
20
19
  @uv_index = uv_index
21
20
  @dewpoint = dewpoint
22
21
  @cloud_cover = cloud_cover
23
22
  end
24
23
 
25
24
  def ==(other)
26
- url == other.url &&
27
25
  observation_time == other.observation_time &&
28
- pressure == other.pressure &&
29
- temperature == other.temperature &&
30
- real_feel == other.real_feel &&
31
- humidity == other.humidity &&
32
- weather_text == other.weather_text &&
33
- weather_icon == other.weather_icon &&
34
- wind_gusts == other.wind_gusts &&
35
- wind_speed == other.wind_speed &&
36
- wind_direction == other.wind_direction &&
37
- visibility == other.visibility &&
38
- precip == other.precip &&
39
- uv_index == other.uv_index &&
40
- dewpoint == other.dewpoint &&
41
- cloud_cover == other.cloud_cover
26
+ pressure == other.pressure &&
27
+ temperature == other.temperature &&
28
+ real_feel == other.real_feel &&
29
+ humidity == other.humidity &&
30
+ weather_text == other.weather_text &&
31
+ weather_icon == other.weather_icon &&
32
+ wind_gusts == other.wind_gusts &&
33
+ wind_speed == other.wind_speed &&
34
+ wind_direction == other.wind_direction &&
35
+ visibility == other.visibility &&
36
+ precipitation == other.precipitation &&
37
+ uv_index == other.uv_index &&
38
+ dewpoint == other.dewpoint &&
39
+ cloud_cover == other.cloud_cover
42
40
  rescue NoMethodError
43
41
  false
44
42
  end
45
43
 
46
44
  def to_s
47
- "url: #{url}, observation_time: #{observation_time}, pressure: #{pressure}, temperature: #{temperature}, real_feel: #{real_feel}, humidity: #{humidity}, weather_text: #{weather_text}, weather_icon: #{weather_icon}, wind_gusts: #{wind_gusts}, wind_speed: #{wind_speed}, wind_direction: #{wind_direction}, visibility: #{visibility}, precip: #{precip}, uv_index: #{uv_index}, dewpoint: #{dewpoint}, cloud_cover: #{cloud_cover}"
45
+ "observation_time: #{observation_time}, pressure: #{pressure}, temperature: #{temperature}, real_feel: #{real_feel}, humidity: #{humidity}, weather_text: #{weather_text}, weather_icon: #{weather_icon}, wind_gusts: #{wind_gusts}, wind_speed: #{wind_speed}, wind_direction: #{wind_direction}, visibility: #{visibility}, precipitation: #{precipitation}, uv_index: #{uv_index}, dewpoint: #{dewpoint}, cloud_cover: #{cloud_cover}"
48
46
  end
49
47
  end
50
48
  end
@@ -0,0 +1,31 @@
1
+ module Accuweather
2
+ module Conditions
3
+ class ForecastDay
4
+ attr_reader :date, :day_of_week, :sunrise, :sunset, :daytime, :nighttime
5
+
6
+ def initialize(date:, day_of_week:, sunrise:, sunset:, daytime:, nighttime:)
7
+ @date = date
8
+ @day_of_week = day_of_week
9
+ @sunrise = sunrise
10
+ @sunset = sunset
11
+ @daytime = daytime
12
+ @nighttime = nighttime
13
+ end
14
+
15
+ def ==(other)
16
+ date == other.date &&
17
+ day_of_week == other.day_of_week &&
18
+ sunrise == other.sunrise &&
19
+ sunset == other.sunset &&
20
+ daytime == other.daytime &&
21
+ nighttime == other.nighttime
22
+ rescue NoMethodError
23
+ false
24
+ end
25
+
26
+ def to_s
27
+ "date: #{date}, day_of_week: #{day_of_week}, sunrise: #{sunrise}, sunset: #{sunset}, daytime: #{daytime}, nighttime: #{nighttime}"
28
+ end
29
+ end
30
+ end
31
+ end
@@ -0,0 +1,59 @@
1
+ module Accuweather
2
+ module Conditions
3
+ class ForecastWeather
4
+ attr_reader :weather_text, :weather_text_long, :weather_icon, :high_temperature, :low_temperature, :real_feel_high, :real_feel_low, :wind_speed, :wind_direction, :wind_gust, :max_uv, :rain_amount, :snow_amount, :ice_amount, :precipitation_amount, :thunderstorm_probability, :rain_probability, :snow_probability, :ice_probability, :precipitation_probability
5
+
6
+ def initialize(weather_text:, weather_text_long:, weather_icon:, high_temperature:, low_temperature:, real_feel_high:, real_feel_low:, wind_speed:, wind_direction:, wind_gust:, max_uv:, rain_amount:, snow_amount:, ice_amount:, precipitation_amount:, thunderstorm_probability:, rain_probability:, snow_probability:, ice_probability:, precipitation_probability:)
7
+ @weather_text = weather_text
8
+ @weather_text_long = weather_text_long
9
+ @weather_icon = weather_icon
10
+ @high_temperature = high_temperature
11
+ @low_temperature = low_temperature
12
+ @real_feel_high = real_feel_high
13
+ @real_feel_low = real_feel_low
14
+ @wind_speed = wind_speed
15
+ @wind_direction = wind_direction
16
+ @wind_gust = wind_gust
17
+ @max_uv = max_uv
18
+ @rain_amount = rain_amount
19
+ @snow_amount = snow_amount
20
+ @ice_amount = ice_amount
21
+ @precipitation_amount = precipitation_amount
22
+ @thunderstorm_probability = thunderstorm_probability
23
+ @rain_probability = rain_probability
24
+ @snow_probability = snow_probability
25
+ @ice_probability = ice_probability
26
+ @precipitation_probability = precipitation_probability
27
+ end
28
+
29
+ def ==(other)
30
+ weather_text == other.weather_text &&
31
+ weather_text_long == other.weather_text_long &&
32
+ weather_icon == other.weather_icon &&
33
+ high_temperature == other.high_temperature &&
34
+ low_temperature == other.low_temperature &&
35
+ real_feel_high == other.real_feel_high &&
36
+ real_feel_low == other.real_feel_low &&
37
+ wind_speed == other.wind_speed &&
38
+ wind_direction == other.wind_direction &&
39
+ wind_gust == other.wind_gust &&
40
+ max_uv == other.max_uv &&
41
+ rain_amount == other.rain_amount &&
42
+ snow_amount == other.snow_amount &&
43
+ ice_amount == other.ice_amount &&
44
+ precipitation_amount == other.precipitation_amount &&
45
+ thunderstorm_probability == other.thunderstorm_probability &&
46
+ rain_probability == other.rain_probability &&
47
+ snow_probability == other.snow_probability &&
48
+ ice_probability == other.ice_probability &&
49
+ precipitation_probability == other.precipitation_probability
50
+ rescue NoMethodError
51
+ false
52
+ end
53
+
54
+ def to_s
55
+ "weather_text: #{weather_text}, weather_text_long: #{weather_text_long}, weather_icon: #{weather_icon}, high_temperature: #{high_temperature}, low_temperature: #{low_temperature}, real_feel_high: #{real_feel_high}, real_feel_low: #{real_feel_low}, wind_speed: #{wind_speed}, wind_direction: #{wind_direction}, wind_gust: #{wind_gust}, max_uv: #{max_uv}, rain_amount: #{rain_amount}, snow_amount: #{snow_amount}, ice_amount: #{ice_amount}, precipitation_amount: #{precipitation_amount}, thunderstorm_probability: #{thunderstorm_probability}, rain_probability: #{rain_probability}, snow_probability: #{snow_probability}, ice_probability: #{ice_probability}, precipitation_probability: #{precipitation_probability}"
56
+ end
57
+ end
58
+ end
59
+ end
@@ -30,8 +30,7 @@ module Accuweather
30
30
 
31
31
  def current
32
32
  current = @doc.css('currentconditions').first
33
- Accuweather::Conditions::Current.new(url: current.css('url').text,
34
- observation_time: current.css('observationtime').text,
33
+ Accuweather::Conditions::Current.new(observation_time: current.css('observationtime').text,
35
34
  pressure: current.css('pressure').text,
36
35
  temperature: current.css('temperature').text,
37
36
  real_feel: current.css('realfeel').text,
@@ -42,12 +41,52 @@ module Accuweather
42
41
  wind_speed: current.css('windspeed').text,
43
42
  wind_direction: current.css('winddirection').text,
44
43
  visibility: current.css('visibility').text,
45
- precip: current.css('precip').text,
44
+ precipitation: current.css('precip').text,
46
45
  uv_index: current.css('uvindex').text,
47
46
  dewpoint: current.css('dewpoint').text,
48
47
  cloud_cover: current.css('cloudcover').text,
49
48
  )
50
49
  end
50
+
51
+
52
+ def forecast
53
+ @doc.css('day').map do |forecast_day|
54
+ day = extract_forcast_time(forecast_day, 'daytime')
55
+ night = extract_forcast_time(forecast_day, 'nighttime')
56
+
57
+ Accuweather::Conditions::ForecastDay.new(date: forecast_day.css('obsdate').text,
58
+ day_of_week: forecast_day.css('daycode').text,
59
+ sunrise: forecast_day.css('sunrise').text,
60
+ sunset: forecast_day.css('sunset').text,
61
+ daytime: day,
62
+ nighttime: night)
63
+ end
64
+ end
65
+
66
+ private
67
+
68
+ def extract_forcast_time(forecast_day, day_or_night)
69
+ Accuweather::Conditions::ForecastWeather.new(weather_text: forecast_day.css("#{day_or_night}/txtshort").text,
70
+ weather_text_long: forecast_day.css("#{day_or_night}/txtlong").text,
71
+ weather_icon: forecast_day.css("#{day_or_night}/weathericon").text,
72
+ high_temperature: forecast_day.css("#{day_or_night}/hightemperature").text,
73
+ low_temperature: forecast_day.css("#{day_or_night}/lowtemperature").text,
74
+ real_feel_high: forecast_day.css("#{day_or_night}/realfeelhigh").text,
75
+ real_feel_low: forecast_day.css("#{day_or_night}/realfeellow").text,
76
+ wind_speed: forecast_day.css("#{day_or_night}/windspeed").text,
77
+ wind_direction: forecast_day.css("#{day_or_night}/winddirection").text,
78
+ wind_gust: forecast_day.css("#{day_or_night}/windgust").text,
79
+ max_uv: forecast_day.css("#{day_or_night}/maxuv").text,
80
+ rain_amount: forecast_day.css("#{day_or_night}/rainamount").text,
81
+ snow_amount: forecast_day.css("#{day_or_night}/snowamount").text,
82
+ ice_amount: forecast_day.css("#{day_or_night}/iceamount").text,
83
+ precipitation_amount: forecast_day.css("#{day_or_night}/precipamount").text,
84
+ thunderstorm_probability: forecast_day.css("#{day_or_night}/tstormprob").text,
85
+ rain_probability: forecast_day.css("#{day_or_night}/rainProbability").text,
86
+ snow_probability: forecast_day.css("#{day_or_night}/snowProbability").text,
87
+ ice_probability: forecast_day.css("#{day_or_night}/iceProbability").text,
88
+ precipitation_probability: forecast_day.css("#{day_or_night}/precipitationProbability").text)
89
+ end
51
90
  end
52
91
  end
53
92
  end
@@ -1,3 +1,3 @@
1
1
  module Accuweather
2
- VERSION = '0.1.3'
2
+ VERSION = '0.2.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: accuweather
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Aschenbach
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-11-26 00:00:00.000000000 Z
11
+ date: 2015-11-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -42,16 +42,16 @@ dependencies:
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ">="
45
+ - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '0'
47
+ version: '3.4'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ">="
52
+ - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '0'
54
+ version: '3.4'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: nokogiri
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -66,9 +66,10 @@ dependencies:
66
66
  - - ">="
67
67
  - !ruby/object:Gem::Version
68
68
  version: '0'
69
- description: |-
70
- A simple web API wrapper to get weather information for cities around the world using the accuweather API. Includes
71
- temperature, pressure, humidity, weather text and GPS coordinates.
69
+ description: Get weather information for cities around the world using the accuweather
70
+ web API. Includes current current conditions for temperature, pressure and humidity.
71
+ Forecasts include temperature highs, lows, "real feels", UV, wind speed, rain, snow,
72
+ ice probabilities and amounts.
72
73
  email:
73
74
  - nick.aschenbach@gmail.com
74
75
  executables: []
@@ -88,6 +89,8 @@ files:
88
89
  - bin/setup
89
90
  - lib/accuweather.rb
90
91
  - lib/accuweather/conditions/current.rb
92
+ - lib/accuweather/conditions/forecast_day.rb
93
+ - lib/accuweather/conditions/forecast_weather.rb
91
94
  - lib/accuweather/conditions/local.rb
92
95
  - lib/accuweather/conditions/parser.rb
93
96
  - lib/accuweather/conditions/units.rb
@@ -116,5 +119,5 @@ rubyforge_project:
116
119
  rubygems_version: 2.4.6
117
120
  signing_key:
118
121
  specification_version: 4
119
- summary: Access current weather report for cities around the world
122
+ summary: Access current and future weather reports for cities around the world
120
123
  test_files: []