weatherboy 1.0.1 → 1.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +4 -0
- data/Gemfile +4 -0
- data/README +28 -29
- data/Rakefile +1 -0
- data/lib/weatherboy.rb +75 -6
- data/lib/weatherboy/alert.rb +1 -1
- data/lib/weatherboy/current.rb +1 -1
- data/lib/weatherboy/forecast.rb +1 -2
- data/lib/weatherboy/radar.rb +1 -2
- data/lib/weatherboy/version.rb +3 -0
- data/lib/weatherboy/webcam.rb +1 -4
- data/weatherboy.gemspec +24 -0
- metadata +32 -47
- data/lib/weatherboy/weatherboy.rb +0 -78
data/.gitignore
ADDED
data/Gemfile
ADDED
data/README
CHANGED
@@ -10,11 +10,11 @@ All classes in Wetherboy are wrapped inside the Weatherboy namespace. The class
|
|
10
10
|
== Setup
|
11
11
|
Require the gem like you would any other gem.
|
12
12
|
|
13
|
-
Then somewhere in your code, create a new Weatherboy
|
13
|
+
Then somewhere in your code, create a new Weatherboy 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
14
|
|
15
|
-
weatherboy = Weatherboy
|
16
|
-
weatherboy = Weatherboy
|
17
|
-
weatherboy = Weatherboy
|
15
|
+
weatherboy = Weatherboy.new(90210)
|
16
|
+
weatherboy = Weatherboy.new("Indianapolis, IN")
|
17
|
+
weatherboy = Weatherboy.new
|
18
18
|
|
19
19
|
You can set/change the location at any time via the location attribute of the object.
|
20
20
|
|
@@ -26,16 +26,16 @@ You can set/change the location at any time via the location attribute of the ob
|
|
26
26
|
The location attribute must be set before you can use any API calls.
|
27
27
|
|
28
28
|
== Retrieving Weather Information
|
29
|
-
Now that you've created a Weatherboy
|
29
|
+
Now that you've created a Weatherboy instance and set a location for it, you're ready to get some weather information.
|
30
30
|
|
31
|
-
===
|
32
|
-
The
|
31
|
+
=== current
|
32
|
+
The current method retrieves the current weather information in the form of a Weatherboy::Current object.
|
33
33
|
|
34
|
-
weatherboy.
|
35
|
-
=>
|
36
|
-
|
34
|
+
w = weatherboy.current
|
35
|
+
=> #<Weatherboy::Current:0x8c3dfe0...
|
36
|
+
w.weather
|
37
37
|
=> "Overcast"
|
38
|
-
|
38
|
+
w.temp_f
|
39
39
|
=> "31"
|
40
40
|
|
41
41
|
=== Attributes of the Weatherboy::Current class
|
@@ -59,14 +59,14 @@ The get_current method retrieves the current weather information in the form of
|
|
59
59
|
* visibility_km
|
60
60
|
|
61
61
|
|
62
|
-
===
|
63
|
-
The get_forecasts method retrieves future weather predictions in the form of an array of Weatherboy::Forecast objects.
|
62
|
+
=== forecasts
|
63
|
+
The get_forecasts method retrieves future weather predictions in the form of an array of Weatherboy::Forecast objects.
|
64
64
|
|
65
|
-
weatherboy.
|
66
|
-
=>
|
67
|
-
|
65
|
+
f = weatherboy.forecasts
|
66
|
+
=> [#<Weatherboy::Forecast:0x8c3dfe0...]
|
67
|
+
f[0].high_f
|
68
68
|
=> "43"
|
69
|
-
|
69
|
+
f[0].conditions
|
70
70
|
=> "Mostly Cloudy"
|
71
71
|
|
72
72
|
=== Attributes of the Weatherboy::Current class
|
@@ -81,16 +81,16 @@ The get_forecasts method retrieves future weather predictions in the form of an
|
|
81
81
|
* text (Full text of forecast)
|
82
82
|
|
83
83
|
|
84
|
-
===
|
85
|
-
The
|
84
|
+
=== alerts ===
|
85
|
+
The alerts method retrieves severe weather alerts and special weather statements in the form of an array of Weatherboy::Alert objects.
|
86
86
|
|
87
|
-
weatherboy.
|
87
|
+
a = weatherboy.alerts
|
88
88
|
=> true
|
89
|
-
|
89
|
+
a.size
|
90
90
|
=> 1
|
91
|
-
|
91
|
+
a[0].date
|
92
92
|
=> "3:40 am PST on January 15, 2008"
|
93
|
-
|
93
|
+
a[0].description
|
94
94
|
=> "Lake Wind Advisory"
|
95
95
|
|
96
96
|
=== Attributes of the Weatherboy::Alert class
|
@@ -99,16 +99,15 @@ The get_alerts method retrieves severe weather alerts and special weather statem
|
|
99
99
|
* message (Usually a HUGE wall of text)
|
100
100
|
|
101
101
|
|
102
|
-
===
|
103
|
-
The
|
104
|
-
It also gets the Weather Underground radar information and stores is as a Weatherboy::Radar object in the radar attribute.
|
102
|
+
=== media
|
103
|
+
The media method retrieves local weather webcams of the location and stores them in a hash containing Weatherboy::Webcam objects and a Weatherboy::Radar object.
|
105
104
|
get_media returns true on a successful result.
|
106
105
|
|
107
|
-
weatherboy.
|
106
|
+
m = weatherboy.media
|
108
107
|
=> true
|
109
|
-
|
108
|
+
m[:radar].image_url
|
110
109
|
=> "http://www.wunderground.com/radar/radblast.asp?ID=IND®ion=b4&lat=39.89311981&lon=-86.18370819"
|
111
|
-
|
110
|
+
m[:webcams][2].image_url
|
112
111
|
=> "http://icons.wunderground.com/webcamramdisk/v/e/VeedersburgBear/1/current.jpg?t=1298845906"
|
113
112
|
|
114
113
|
=== Attributes of the Weatherboy::Radar class
|
data/Rakefile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
data/lib/weatherboy.rb
CHANGED
@@ -1,6 +1,75 @@
|
|
1
|
-
require
|
2
|
-
require
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
1
|
+
require "weatherboy/version"
|
2
|
+
require "weatherboy/current"
|
3
|
+
require "weatherboy/alert"
|
4
|
+
require "weatherboy/forecast"
|
5
|
+
require "weatherboy/webcam"
|
6
|
+
require "weatherboy/radar"
|
7
|
+
|
8
|
+
class Weatherboy
|
9
|
+
require 'net/http'
|
10
|
+
require 'rexml/document'
|
11
|
+
|
12
|
+
attr_accessor :location
|
13
|
+
# From http://wiki.wunderground.com/index.php/API_-_XML
|
14
|
+
|
15
|
+
BASE_URL = "http://api.wunderground.com/auto/wui/geo/"
|
16
|
+
|
17
|
+
def initialize(loc=nil)
|
18
|
+
@location = loc
|
19
|
+
end
|
20
|
+
|
21
|
+
def current
|
22
|
+
verify
|
23
|
+
doc = makeCall(BASE_URL+"WXCurrentObXML/index.xml?query=#{@location}")
|
24
|
+
Weatherboy::Current.new(doc)
|
25
|
+
end
|
26
|
+
|
27
|
+
def alerts
|
28
|
+
verify
|
29
|
+
alerts = []
|
30
|
+
doc = makeCall(BASE_URL+"AlertsXML/index.xml?query=#{@location}")
|
31
|
+
doc.elements.each('alerts/alert/AlertItem') do |alert_doc|
|
32
|
+
alerts << Weatherboy::Alert.new(alert_doc)
|
33
|
+
end
|
34
|
+
alerts
|
35
|
+
end
|
36
|
+
|
37
|
+
def forecasts
|
38
|
+
verify
|
39
|
+
forecasts = []
|
40
|
+
doc = makeCall(BASE_URL+"ForecastXML/index.xml?query=#{@location}")
|
41
|
+
doc.elements.each('forecast/simpleforecast/forecastday') do |forcastday|
|
42
|
+
this_forecast = Weatherboy::Forecast.new
|
43
|
+
this_forecast.first_pass(forcastday)
|
44
|
+
forecasts << this_forecast
|
45
|
+
end
|
46
|
+
i = 0
|
47
|
+
doc.elements.each('forecast/txt_forecast/forecastday') do |forecastday|
|
48
|
+
forecasts[i].second_pass(forecastday)
|
49
|
+
i = i + 1
|
50
|
+
end
|
51
|
+
forecasts
|
52
|
+
end
|
53
|
+
|
54
|
+
def media
|
55
|
+
verify
|
56
|
+
media = {:webcams => [], :radar => nil}
|
57
|
+
doc = makeCall(BASE_URL+"GeoLookupXML/index.xml?query=#{@location}")
|
58
|
+
doc.elements.each('location/webcams/cam') do |wc|
|
59
|
+
media[:webcams] << Weatherboy::Webcam.new(wc)
|
60
|
+
end
|
61
|
+
media[:radar] = Weatherboy::Radar.new(doc.elements['location/radar'])
|
62
|
+
media
|
63
|
+
end
|
64
|
+
|
65
|
+
|
66
|
+
private
|
67
|
+
|
68
|
+
def verify
|
69
|
+
raise "Weatherboy: Location not set. Can't make call." if @location.nil?
|
70
|
+
end
|
71
|
+
|
72
|
+
def makeCall(url)
|
73
|
+
return REXML::Document.new( Net::HTTP.get_response(URI.parse(url)).body)
|
74
|
+
end
|
75
|
+
end
|
data/lib/weatherboy/alert.rb
CHANGED
data/lib/weatherboy/current.rb
CHANGED
data/lib/weatherboy/forecast.rb
CHANGED
data/lib/weatherboy/radar.rb
CHANGED
data/lib/weatherboy/webcam.rb
CHANGED
@@ -1,6 +1,5 @@
|
|
1
|
-
|
1
|
+
class Weatherboy
|
2
2
|
class Webcam
|
3
|
-
|
4
3
|
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
4
|
|
6
5
|
def initialize(doc)
|
@@ -21,7 +20,5 @@ module Weatherboy
|
|
21
20
|
@widget_url = doc.elements['WIDGETCURRENTIMAGEURL'].text
|
22
21
|
@cam_url = doc.elements['CAMURL'].text
|
23
22
|
end
|
24
|
-
|
25
23
|
end
|
26
|
-
|
27
24
|
end
|
data/weatherboy.gemspec
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "weatherboy/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "weatherboy"
|
7
|
+
s.version = Weatherboy::VERSION
|
8
|
+
s.authors = ["Tony Drake"]
|
9
|
+
s.email = ["t27duck@gmail.com"]
|
10
|
+
s.homepage = ""
|
11
|
+
s.summary = %q{Retrieve weather information from Weather Underground}
|
12
|
+
s.description = %q{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.}
|
13
|
+
|
14
|
+
s.rubyforge_project = "weatherboy"
|
15
|
+
|
16
|
+
s.files = `git ls-files`.split("\n")
|
17
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
18
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
19
|
+
s.require_paths = ["lib"]
|
20
|
+
|
21
|
+
# specify any dependencies here; for example:
|
22
|
+
# s.add_development_dependency "rspec"
|
23
|
+
# s.add_runtime_dependency "rest-client"
|
24
|
+
end
|
metadata
CHANGED
@@ -1,76 +1,61 @@
|
|
1
|
-
--- !ruby/object:Gem::Specification
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
2
|
name: weatherboy
|
3
|
-
version: !ruby/object:Gem::Version
|
4
|
-
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.2
|
5
5
|
prerelease:
|
6
|
-
segments:
|
7
|
-
- 1
|
8
|
-
- 0
|
9
|
-
- 1
|
10
|
-
version: 1.0.1
|
11
6
|
platform: ruby
|
12
|
-
authors:
|
7
|
+
authors:
|
13
8
|
- Tony Drake
|
14
9
|
autorequire:
|
15
10
|
bindir: bin
|
16
11
|
cert_chain: []
|
17
|
-
|
18
|
-
date: 2011-02-28 00:00:00 -10:00
|
12
|
+
date: 2011-10-29 00:00:00.000000000 -04:00
|
19
13
|
default_executable:
|
20
14
|
dependencies: []
|
21
|
-
|
22
|
-
|
23
|
-
|
15
|
+
description: A Ruby Gem that connects to Weather Underground's XML API feed. Provides
|
16
|
+
current conditions, future forecasts, weather alerts, and links to weather camera
|
17
|
+
images and weather radars.
|
18
|
+
email:
|
24
19
|
- t27duck@gmail.com
|
25
20
|
executables: []
|
26
|
-
|
27
21
|
extensions: []
|
28
|
-
|
29
|
-
|
30
|
-
-
|
31
|
-
|
22
|
+
extra_rdoc_files: []
|
23
|
+
files:
|
24
|
+
- .gitignore
|
25
|
+
- Gemfile
|
32
26
|
- README
|
27
|
+
- Rakefile
|
33
28
|
- lib/weatherboy.rb
|
34
|
-
- lib/weatherboy/webcam.rb
|
35
|
-
- lib/weatherboy/weatherboy.rb
|
36
|
-
- lib/weatherboy/radar.rb
|
37
|
-
- lib/weatherboy/forecast.rb
|
38
29
|
- lib/weatherboy/alert.rb
|
39
30
|
- lib/weatherboy/current.rb
|
31
|
+
- lib/weatherboy/forecast.rb
|
32
|
+
- lib/weatherboy/radar.rb
|
33
|
+
- lib/weatherboy/version.rb
|
34
|
+
- lib/weatherboy/webcam.rb
|
35
|
+
- weatherboy.gemspec
|
40
36
|
has_rdoc: true
|
41
|
-
homepage:
|
37
|
+
homepage: ''
|
42
38
|
licenses: []
|
43
|
-
|
44
39
|
post_install_message:
|
45
|
-
rdoc_options:
|
46
|
-
|
47
|
-
- README
|
48
|
-
require_paths:
|
40
|
+
rdoc_options: []
|
41
|
+
require_paths:
|
49
42
|
- lib
|
50
|
-
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
51
44
|
none: false
|
52
|
-
requirements:
|
53
|
-
- -
|
54
|
-
- !ruby/object:Gem::Version
|
55
|
-
|
56
|
-
|
57
|
-
- 0
|
58
|
-
version: "0"
|
59
|
-
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
requirements:
|
46
|
+
- - ! '>='
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: '0'
|
49
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
60
50
|
none: false
|
61
|
-
requirements:
|
62
|
-
- -
|
63
|
-
- !ruby/object:Gem::Version
|
64
|
-
|
65
|
-
segments:
|
66
|
-
- 0
|
67
|
-
version: "0"
|
51
|
+
requirements:
|
52
|
+
- - ! '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
68
55
|
requirements: []
|
69
|
-
|
70
56
|
rubyforge_project: weatherboy
|
71
57
|
rubygems_version: 1.5.2
|
72
58
|
signing_key:
|
73
59
|
specification_version: 3
|
74
60
|
summary: Retrieve weather information from Weather Underground
|
75
61
|
test_files: []
|
76
|
-
|
@@ -1,78 +0,0 @@
|
|
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
|