alexmchale-wunderground-api 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/README.markdown +0 -0
- data/lib/wunderground.rb +30 -0
- metadata +55 -0
data/README.markdown
ADDED
File without changes
|
data/lib/wunderground.rb
ADDED
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'xmlsimple'
|
3
|
+
require 'net/http'
|
4
|
+
require 'cgi'
|
5
|
+
require 'andand'
|
6
|
+
require 'pp'
|
7
|
+
|
8
|
+
class Hash
|
9
|
+
def to_url
|
10
|
+
map {|key, value| "#{CGI.escape key.to_s}=#{CGI.escape value.to_s}"}.join "&"
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
class Wunderground
|
15
|
+
def initialize(location)
|
16
|
+
@location = location
|
17
|
+
@params = { :query => location }.to_url
|
18
|
+
end
|
19
|
+
|
20
|
+
def forecast
|
21
|
+
data = Net::HTTP.get(URI.parse "http://api.wunderground.com/auto/wui/geo/ForecastXML/index.xml?#{@params}")
|
22
|
+
XmlSimple.xml_in(data, { 'ForceArray' => false }).andand['simpleforecast'].andand['forecastday']
|
23
|
+
end
|
24
|
+
|
25
|
+
def simple_forecast(days = 3)
|
26
|
+
forecast.andand[0, days.to_i].andand.each do |day|
|
27
|
+
printf "%s: %s, High %s Low %s\n", day['date']['weekday'], day['conditions'], day['high']['fahrenheit'], day['low']['fahrenheit']
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
metadata
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: alexmchale-wunderground-api
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alex McHale
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
|
12
|
+
date: 2009-03-10 00:00:00 -07:00
|
13
|
+
default_executable:
|
14
|
+
dependencies: []
|
15
|
+
|
16
|
+
description:
|
17
|
+
email: alexmchale@gmail.com
|
18
|
+
executables: []
|
19
|
+
|
20
|
+
extensions: []
|
21
|
+
|
22
|
+
extra_rdoc_files:
|
23
|
+
- README.markdown
|
24
|
+
files:
|
25
|
+
- README.markdown
|
26
|
+
- lib/wunderground.rb
|
27
|
+
has_rdoc: true
|
28
|
+
homepage: http://github.com/alexmchale/wunderground-api
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options:
|
31
|
+
- --inline-source
|
32
|
+
- --charset=UTF-8
|
33
|
+
require_paths:
|
34
|
+
- lib
|
35
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
36
|
+
requirements:
|
37
|
+
- - ">="
|
38
|
+
- !ruby/object:Gem::Version
|
39
|
+
version: "0"
|
40
|
+
version:
|
41
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
version:
|
47
|
+
requirements: []
|
48
|
+
|
49
|
+
rubyforge_project:
|
50
|
+
rubygems_version: 1.2.0
|
51
|
+
signing_key:
|
52
|
+
specification_version: 2
|
53
|
+
summary: An API to Weather Underground.
|
54
|
+
test_files: []
|
55
|
+
|