weatherboy 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README +134 -0
- data/lib/weatherboy/alert.rb +14 -0
- data/lib/weatherboy/current.rb +30 -0
- data/lib/weatherboy/forecast.rb +23 -0
- data/lib/weatherboy/radar.rb +13 -0
- data/lib/weatherboy/weatherboy.rb +78 -0
- data/lib/weatherboy/webcam.rb +27 -0
- data/lib/weatherboy.rb +6 -0
- metadata +76 -0
data/README
ADDED
@@ -0,0 +1,134 @@
|
|
1
|
+
== Weatherboy
|
2
|
+
|
3
|
+
Weatherboy is an easy-to-use gem that interfaces with the wunderground.com weather XML feeds.
|
4
|
+
You are responsible for following Weather Underground's Terms of Service when using thier data feeds.
|
5
|
+
|
6
|
+
TOS: http://wiki.wunderground.com/index.php/API_-_XML#API_Terms_Of_Service
|
7
|
+
|
8
|
+
All classes in Wetherboy are wrapped inside the Weatherboy namespace. The class you directly interface with is the Core class. All other classes in the gem hold individual bits of weather info (current conditions, alerts, etc) that the Core class invokes.
|
9
|
+
|
10
|
+
== Setup
|
11
|
+
Require the gem like you would any other gem.
|
12
|
+
|
13
|
+
Then somewhere in your code, create a new Weatherboy::Core object. The initilize method can take an area code, airport code, localweather station code, a city/state combo, or no arguments. Passing a location into the initilize method sets the location attribute used for all API calls.
|
14
|
+
|
15
|
+
weatherboy = Weatherboy::Core.new(90210)
|
16
|
+
weatherboy = Weatherboy::Core.new("Indianapolis, IN")
|
17
|
+
weatherboy = Weatherboy::Core.new
|
18
|
+
|
19
|
+
You can set/change the location at any time via the location attribute of the object.
|
20
|
+
|
21
|
+
weatherboy.location = "New York, NY"
|
22
|
+
weatherboy.location = 46220
|
23
|
+
weatherboy.location
|
24
|
+
=> 46220
|
25
|
+
|
26
|
+
The location attribute must be set before you can use any API calls.
|
27
|
+
|
28
|
+
== Retrieving Weather Information
|
29
|
+
Now that you've created a Weatherboy::Core instance and set a location for it, you're ready to get some weather information.
|
30
|
+
|
31
|
+
=== get_current
|
32
|
+
The get_current method retrieves the current weather information in the form of a Weatherboy::Current object. It stores the result in the current attribute of the Core class. get_current returns true on a successful result.
|
33
|
+
|
34
|
+
weatherboy.get_current
|
35
|
+
=> true
|
36
|
+
weatherboy.current.weather
|
37
|
+
=> "Overcast"
|
38
|
+
weatherboy.current.temp_f
|
39
|
+
=> "31"
|
40
|
+
|
41
|
+
=== Attributes of the Weatherboy::Current class
|
42
|
+
* icon (URL)
|
43
|
+
* weather
|
44
|
+
* temp_f
|
45
|
+
* temp_c
|
46
|
+
* relative_humidity
|
47
|
+
* wind_dir
|
48
|
+
* wind_mph
|
49
|
+
* pressure_mb
|
50
|
+
* pressure_in
|
51
|
+
* dewpoint_f
|
52
|
+
* dewpoint_c
|
53
|
+
* heat_index_f
|
54
|
+
* heat_index_c
|
55
|
+
* windchill_f
|
56
|
+
* windchill_c
|
57
|
+
* windchill_c
|
58
|
+
* visibility_mi
|
59
|
+
* visibility_km
|
60
|
+
|
61
|
+
|
62
|
+
=== get_forecasts
|
63
|
+
The get_forecasts method retrieves future weather predictions in the form of an array of Weatherboy::Forecast objects. It stores the result in the forecsts attribute of the Core class. get_forecasts returns true on a successful result.
|
64
|
+
|
65
|
+
weatherboy.get_forecasts
|
66
|
+
=> true
|
67
|
+
weatherboy.forecasts[0].high_f
|
68
|
+
=> "43"
|
69
|
+
weatherboy.forecasts[0].conditions
|
70
|
+
=> "Mostly Cloudy"
|
71
|
+
|
72
|
+
=== Attributes of the Weatherboy::Current class
|
73
|
+
* high_f
|
74
|
+
* high_c
|
75
|
+
* low_f
|
76
|
+
* low_c
|
77
|
+
* conditions
|
78
|
+
* icon (URL)
|
79
|
+
* pop (Possibility of Precipitation)
|
80
|
+
* title (This Afternoon, Tonight, Monday, etc)
|
81
|
+
* text (Full text of forecast)
|
82
|
+
|
83
|
+
|
84
|
+
=== get_alerts ===
|
85
|
+
The get_alerts method retrieves severe weather alerts and special weather statements in the form of an array of Weatherboy::Alert objects. It stores the result in the alerts attribute of the Core class. get_alerts returns true on a successful result.
|
86
|
+
|
87
|
+
weatherboy.get_alerts
|
88
|
+
=> true
|
89
|
+
weatherboy.alerts.size
|
90
|
+
=> 1
|
91
|
+
weatherboy.alerts[0].date
|
92
|
+
=> "3:40 am PST on January 15, 2008"
|
93
|
+
weatherboy.alerts[0].description
|
94
|
+
=> "Lake Wind Advisory"
|
95
|
+
|
96
|
+
=== Attributes of the Weatherboy::Alert class
|
97
|
+
* description
|
98
|
+
* date (Just the string returned from the XML. Not a date object)
|
99
|
+
* message (Usually a HUGE wall of text)
|
100
|
+
|
101
|
+
|
102
|
+
=== get_media
|
103
|
+
The get_media method retrieves local weather webcams of the location and stores them in an array of Weatherboy::Webcam objects in the webcams attribute.
|
104
|
+
It also gets the Weather Underground radar information and stores is as a Weatherboy::Radar object in the radar attribute.
|
105
|
+
get_media returns true on a successful result.
|
106
|
+
|
107
|
+
weatherboy.get_media
|
108
|
+
=> true
|
109
|
+
weatherboy.radar.image_url
|
110
|
+
=> "http://www.wunderground.com/radar/radblast.asp?ID=IND®ion=b4&lat=39.89311981&lon=-86.18370819"
|
111
|
+
weatherboy.webcams[2].image_url
|
112
|
+
=> "http://icons.wunderground.com/webcamramdisk/v/e/VeedersburgBear/1/current.jpg?t=1298845906"
|
113
|
+
|
114
|
+
=== Attributes of the Weatherboy::Radar class
|
115
|
+
* image_url
|
116
|
+
* url
|
117
|
+
|
118
|
+
=== Attributes of the Weatherboy::Webcam class
|
119
|
+
* handle
|
120
|
+
* camid
|
121
|
+
* assoc_station_id
|
122
|
+
* link
|
123
|
+
* link_text
|
124
|
+
* organization
|
125
|
+
* cameratype
|
126
|
+
* neighborhood
|
127
|
+
* zip
|
128
|
+
* city
|
129
|
+
* state
|
130
|
+
* country
|
131
|
+
* updated
|
132
|
+
* image_url
|
133
|
+
* widget_url
|
134
|
+
* cam_url
|
@@ -0,0 +1,14 @@
|
|
1
|
+
module Weatherboy
|
2
|
+
class Alert
|
3
|
+
|
4
|
+
attr_reader :description, :date, :message
|
5
|
+
|
6
|
+
def initialize(doc)
|
7
|
+
@description = doc.elements['description'].text
|
8
|
+
@date = doc.elements['date'].text
|
9
|
+
@message = doc.elements['message'].text
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
module Weatherboy
|
2
|
+
class Current
|
3
|
+
|
4
|
+
attr_reader :icon, :weather, :temp_f, :temp_c, :relative_humidity, :wind_dir, :wind_mph, :pressure_mb, :pressure_in, :dewpoint_f, :dewpoint_c
|
5
|
+
attr_reader :heat_index_f, :heat_index_c, :windchill_f, :windchill_c, :windchill_c, :visibility_mi, :visibility_km
|
6
|
+
|
7
|
+
def initialize(doc)
|
8
|
+
@icon = "http://icons-ecast.wxug.com/graphics/conds/#{doc.elements['current_observation/icon'].text}.gif"
|
9
|
+
@weather = doc.elements['current_observation/weather'].text
|
10
|
+
@temp_f = doc.elements['current_observation/temp_f'].text
|
11
|
+
@temp_c = doc.elements['current_observation/temp_c'].text
|
12
|
+
@relative_humidity = doc.elements['current_observation/relative_humidity'].text
|
13
|
+
@wind_dir = doc.elements['current_observation/wind_dir'].text
|
14
|
+
@wind_mph = doc.elements['current_observation/wind_mph'].text
|
15
|
+
@pressure_mb = doc.elements['current_observation/pressure_mb'].text
|
16
|
+
@pressure_in = doc.elements['current_observation/pressure_in'].text
|
17
|
+
@dewpoint_f = doc.elements['current_observation/dewpoint_f'].text
|
18
|
+
@dewpoint_c = doc.elements['current_observation/dewpoint_c'].text
|
19
|
+
@heat_index_f = doc.elements['current_observation/heat_index_f'].text
|
20
|
+
@heat_index_c = doc.elements['current_observation/heat_index_c'].text
|
21
|
+
@windchill_f = doc.elements['current_observation/windchill_f'].text
|
22
|
+
@windchill_c = doc.elements['current_observation/windchill_c'].text
|
23
|
+
@windchill_c = doc.elements['current_observation/windchill_c'].text
|
24
|
+
@visibility_mi = doc.elements['current_observation/visibility_mi'].text
|
25
|
+
@visibility_km = doc.elements['current_observation/visibility_km'].text
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module Weatherboy
|
2
|
+
class Forecast
|
3
|
+
|
4
|
+
attr_reader :high_f, :high_c, :low_f, :low_c, :conditions, :icon, :pop, :title, :text
|
5
|
+
|
6
|
+
def first_pass(doc)
|
7
|
+
@high_f = doc.elements['high/fahrenheit'].text
|
8
|
+
@high_c = doc.elements['high/celsius'].text
|
9
|
+
@low_f = doc.elements['low/fahrenheit'].text
|
10
|
+
@low_c = doc.elements['low/celsius'].text
|
11
|
+
@conditions = doc.elements['conditions'].text
|
12
|
+
@icon = "http://icons-ecast.wxug.com/graphics/conds/#{doc.elements['icon'].text}.gif"
|
13
|
+
@pop = doc.elements['pop'].text
|
14
|
+
end
|
15
|
+
|
16
|
+
def second_pass(doc)
|
17
|
+
@title = doc.elements['title'].text
|
18
|
+
@text = doc.elements['fcttext'].text
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
module Weatherboy
|
2
|
+
class Core
|
3
|
+
require 'net/http'
|
4
|
+
require 'rexml/document'
|
5
|
+
|
6
|
+
attr_reader :current, :alerts, :forecasts, :webcams, :radar
|
7
|
+
attr_accessor :location, :debug
|
8
|
+
#From http://wiki.wunderground.com/index.php/API_-_XML
|
9
|
+
|
10
|
+
BASE_URL = "http://api.wunderground.com/auto/wui/geo/"
|
11
|
+
|
12
|
+
def initialize(loc=nil)
|
13
|
+
@location = loc
|
14
|
+
end
|
15
|
+
|
16
|
+
def get_current
|
17
|
+
verify
|
18
|
+
doc = makeCall(BASE_URL+"WXCurrentObXML/index.xml?query=#{@location}")
|
19
|
+
@current = Current.new(doc)
|
20
|
+
true
|
21
|
+
end
|
22
|
+
|
23
|
+
def get_alerts
|
24
|
+
verify
|
25
|
+
@alerts = []
|
26
|
+
doc = makeCall(BASE_URL+"AlertsXML/index.xml?query=#{@location}")
|
27
|
+
doc.elements.each('alerts/alert/AlertItem') do |alert_doc|
|
28
|
+
@alerts << Alert.new(alert_doc)
|
29
|
+
end
|
30
|
+
true
|
31
|
+
end
|
32
|
+
|
33
|
+
def get_forecasts
|
34
|
+
verify
|
35
|
+
@forecasts = []
|
36
|
+
doc = makeCall(BASE_URL+"ForecastXML/index.xml?query=#{@location}")
|
37
|
+
doc.elements.each('forecast/simpleforecast/forecastday') do |forcastday|
|
38
|
+
this_forecast = Forecast.new
|
39
|
+
this_forecast.first_pass(forcastday)
|
40
|
+
@forecasts << this_forecast
|
41
|
+
end
|
42
|
+
i = 0
|
43
|
+
doc.elements.each('forecast/txt_forecast/forecastday') do |forecastday|
|
44
|
+
@forecasts[i].second_pass(forecastday)
|
45
|
+
i = i + 1
|
46
|
+
end
|
47
|
+
true
|
48
|
+
end
|
49
|
+
|
50
|
+
def get_media
|
51
|
+
verify
|
52
|
+
@webcams = []
|
53
|
+
@radar = nil
|
54
|
+
doc = makeCall(BASE_URL+"GeoLookupXML/index.xml?query=#{@location}")
|
55
|
+
doc.elements.each('location/webcams/cam') do |webcam|
|
56
|
+
@webcams << Webcam.new(webcam)
|
57
|
+
end
|
58
|
+
@radar = Radar.new(doc.elements['location/radar'])
|
59
|
+
true
|
60
|
+
end
|
61
|
+
|
62
|
+
|
63
|
+
protected
|
64
|
+
|
65
|
+
def verify
|
66
|
+
raise "Weatherboy: Location not set. Can't make call." if @location.nil?
|
67
|
+
end
|
68
|
+
|
69
|
+
def makeCall(url)
|
70
|
+
return REXML::Document.new( Net::HTTP.get_response(URI.parse(url)).body )
|
71
|
+
end
|
72
|
+
|
73
|
+
def debugging?
|
74
|
+
@debug == true
|
75
|
+
end
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
module Weatherboy
|
2
|
+
class Webcam
|
3
|
+
|
4
|
+
attr_reader :handle, :camid, :assoc_station_id, :link, :link_text, :organization, :cameratype, :neighborhood, :zip, :city, :state, :country, :updated, :image_url, :widget_url, :cam_url
|
5
|
+
|
6
|
+
def initialize(doc)
|
7
|
+
@handle = doc.elements['handle'].text
|
8
|
+
@camid = doc.elements['camid'].text
|
9
|
+
@assoc_station_id = doc.elements['assoc_station_id'].text
|
10
|
+
@link = doc.elements['link'].text
|
11
|
+
@link_text = doc.elements['linktext'].text
|
12
|
+
@organization = doc.elements['organization'].text
|
13
|
+
@cameratype = doc.elements['cameratype'].text
|
14
|
+
@neighborhood = doc.elements['neighborhood'].text
|
15
|
+
@zip = doc.elements['zip'].text
|
16
|
+
@city = doc.elements['city'].text
|
17
|
+
@state = doc.elements['state'].text
|
18
|
+
@country = doc.elements['country'].text
|
19
|
+
@updated = doc.elements['updated'].text
|
20
|
+
@image_url = doc.elements['CURRENTIMAGEURL'].text
|
21
|
+
@widget_url = doc.elements['WIDGETCURRENTIMAGEURL'].text
|
22
|
+
@cam_url = doc.elements['CAMURL'].text
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
data/lib/weatherboy.rb
ADDED
metadata
ADDED
@@ -0,0 +1,76 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: weatherboy
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 21
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 1.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Tony Drake
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-02-28 00:00:00 -10:00
|
19
|
+
default_executable:
|
20
|
+
dependencies: []
|
21
|
+
|
22
|
+
description: A Ruby Gem that connects to Weather Underground's XML API feed. Provides current conditions, future forecasts, weather alerts, and links to weather camera images and weather radars.
|
23
|
+
email:
|
24
|
+
- t27duck@gmail.com
|
25
|
+
executables: []
|
26
|
+
|
27
|
+
extensions: []
|
28
|
+
|
29
|
+
extra_rdoc_files:
|
30
|
+
- README
|
31
|
+
files:
|
32
|
+
- README
|
33
|
+
- lib/weatherboy.rb
|
34
|
+
- lib/weatherboy/webcam.rb
|
35
|
+
- lib/weatherboy/weatherboy.rb
|
36
|
+
- lib/weatherboy/radar.rb
|
37
|
+
- lib/weatherboy/forecast.rb
|
38
|
+
- lib/weatherboy/alert.rb
|
39
|
+
- lib/weatherboy/current.rb
|
40
|
+
has_rdoc: true
|
41
|
+
homepage: https://bitbucket.org/t27duck/weatherboy
|
42
|
+
licenses: []
|
43
|
+
|
44
|
+
post_install_message:
|
45
|
+
rdoc_options:
|
46
|
+
- --main
|
47
|
+
- README
|
48
|
+
require_paths:
|
49
|
+
- lib
|
50
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
hash: 3
|
56
|
+
segments:
|
57
|
+
- 0
|
58
|
+
version: "0"
|
59
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
|
+
none: false
|
61
|
+
requirements:
|
62
|
+
- - ">="
|
63
|
+
- !ruby/object:Gem::Version
|
64
|
+
hash: 3
|
65
|
+
segments:
|
66
|
+
- 0
|
67
|
+
version: "0"
|
68
|
+
requirements: []
|
69
|
+
|
70
|
+
rubyforge_project: weatherboy
|
71
|
+
rubygems_version: 1.5.2
|
72
|
+
signing_key:
|
73
|
+
specification_version: 3
|
74
|
+
summary: Retrieve weather information from Weather Underground
|
75
|
+
test_files: []
|
76
|
+
|