gwx 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Gemfile +1 -0
- data/Gemfile.lock +13 -0
- data/lib/gwx.rb +48 -0
- data/lib/gwx/current_conditions.rb +32 -0
- data/lib/gwx/forecast_conditions.rb +27 -0
- data/lib/gwx/forecast_information.rb +36 -0
- metadata +51 -0
data/Gemfile
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
gem "httparty", "~>0.8.3"
|
data/Gemfile.lock
ADDED
data/lib/gwx.rb
ADDED
@@ -0,0 +1,48 @@
|
|
1
|
+
require "httparty"
|
2
|
+
|
3
|
+
class GoogleWeather
|
4
|
+
include HTTParty
|
5
|
+
|
6
|
+
def initialize(location)
|
7
|
+
result = validate_location(location)
|
8
|
+
unless result.class == String
|
9
|
+
@wx = result
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def current
|
14
|
+
@current ||= Current.new(@wx)
|
15
|
+
end
|
16
|
+
|
17
|
+
def information
|
18
|
+
@information ||= Information.new(@wx)
|
19
|
+
end
|
20
|
+
|
21
|
+
def forecast
|
22
|
+
@forecast ||= Array.new
|
23
|
+
4.times do |day|
|
24
|
+
@forecast << Forecast.new(@wx, day)
|
25
|
+
end
|
26
|
+
@forecast
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def validate_location(location)
|
32
|
+
request = HTTParty.get("http://www.google.com/ig/api?weather=#{location}")
|
33
|
+
response = request["xml_api_reply"]["weather"]
|
34
|
+
case response.include?("problem_cause")
|
35
|
+
when true
|
36
|
+
result = "Invalid Location"
|
37
|
+
when false
|
38
|
+
result = response
|
39
|
+
end
|
40
|
+
return result
|
41
|
+
end
|
42
|
+
|
43
|
+
end
|
44
|
+
|
45
|
+
|
46
|
+
require_relative "gwx/current_conditions"
|
47
|
+
require_relative "gwx/forecast_conditions"
|
48
|
+
require_relative "gwx/forecast_information"
|
@@ -0,0 +1,32 @@
|
|
1
|
+
class GoogleWeather::Current
|
2
|
+
attr_accessor :current_conditions,:condition, :temp_f, :temp_c, :humidity, :icon,
|
3
|
+
:wind_condition
|
4
|
+
|
5
|
+
def initialize(wx)
|
6
|
+
@current_conditions = wx["current_conditions"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def condition
|
10
|
+
@conditon ||= @current_conditions["condition"]["data"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def temp_f
|
14
|
+
@temp_f ||= @current_conditions["temp_f"]["data"].to_i
|
15
|
+
end
|
16
|
+
|
17
|
+
def temp_c
|
18
|
+
@temp_c ||= @current_conditions["temp_c"]["data"].to_i
|
19
|
+
end
|
20
|
+
|
21
|
+
def humidity
|
22
|
+
@humidity ||= @current_conditions["humidity"]["data"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def icon
|
26
|
+
@icon ||= @current_conditions["icon"]["data"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def wind_condition
|
30
|
+
@wind_condition ||= @current_conditions["wind_condition"]["data"]
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,27 @@
|
|
1
|
+
class GoogleWeather::Forecast
|
2
|
+
attr_accessor :forecast_conditions, :day_of_week, :icon, :low, :high, :condition
|
3
|
+
|
4
|
+
def initialize(wx, day)
|
5
|
+
@forecast_conditions = wx["forecast_conditions"][day]
|
6
|
+
end
|
7
|
+
|
8
|
+
def day_of_week
|
9
|
+
@day_of_week = @forecast_conditions["day_of_week"]["data"]
|
10
|
+
end
|
11
|
+
|
12
|
+
def icon
|
13
|
+
@icon = @forecast_conditions["icon"]["data"]
|
14
|
+
end
|
15
|
+
|
16
|
+
def low
|
17
|
+
@low = @forecast_conditions["low"]["data"].to_i
|
18
|
+
end
|
19
|
+
|
20
|
+
def high
|
21
|
+
@high = @forecast_conditions["high"]["data"].to_i
|
22
|
+
end
|
23
|
+
|
24
|
+
def condition
|
25
|
+
@condition = @forecast_conditions["condition"]["data"]
|
26
|
+
end
|
27
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
class GoogleWeather::Information
|
2
|
+
attr_accessor :forecast_information, :city, :postal_code, :latitude, :longitude,
|
3
|
+
:forecast_date_time, :current_date_time, :unit_system
|
4
|
+
|
5
|
+
def initialize(wx)
|
6
|
+
@forecast_information = wx["forecast_information"]
|
7
|
+
end
|
8
|
+
|
9
|
+
def city
|
10
|
+
@city ||= @forecast_information["city"]["data"]
|
11
|
+
end
|
12
|
+
|
13
|
+
def postal_code
|
14
|
+
@postal_code ||= @forecast_information["city"]["data"]
|
15
|
+
end
|
16
|
+
|
17
|
+
def latitude
|
18
|
+
@latitude ||= @forecast_information["latitude_e6"]["data"]
|
19
|
+
end
|
20
|
+
|
21
|
+
def longitude
|
22
|
+
@longitude ||= @forecast_information["longitude_e6"]["data"]
|
23
|
+
end
|
24
|
+
|
25
|
+
def forecast_date
|
26
|
+
@forecast_date ||= @forecast_information["forecast_time"]["data"]
|
27
|
+
end
|
28
|
+
|
29
|
+
def current_date_time
|
30
|
+
@current_date_time ||= @forecast_information["current_date_time"]["data"]
|
31
|
+
end
|
32
|
+
|
33
|
+
def unit_system
|
34
|
+
@unit_system ||= @forecast_information["unit_system"]["data"]
|
35
|
+
end
|
36
|
+
end
|
metadata
ADDED
@@ -0,0 +1,51 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: gwx
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Austin Spires
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-05-17 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Object-oriented wrapper for Google's unofficial weather API. Not intended
|
15
|
+
for production use.
|
16
|
+
email: austinspires@gmail.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- lib/gwx.rb
|
22
|
+
- lib/gwx/current_conditions.rb
|
23
|
+
- lib/gwx/forecast_conditions.rb
|
24
|
+
- lib/gwx/forecast_information.rb
|
25
|
+
- Gemfile
|
26
|
+
- Gemfile.lock
|
27
|
+
homepage: https://github.com/aspires/gwx
|
28
|
+
licenses: []
|
29
|
+
post_install_message:
|
30
|
+
rdoc_options: []
|
31
|
+
require_paths:
|
32
|
+
- lib
|
33
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
34
|
+
none: false
|
35
|
+
requirements:
|
36
|
+
- - ! '>='
|
37
|
+
- !ruby/object:Gem::Version
|
38
|
+
version: '0'
|
39
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
40
|
+
none: false
|
41
|
+
requirements:
|
42
|
+
- - ! '>='
|
43
|
+
- !ruby/object:Gem::Version
|
44
|
+
version: '0'
|
45
|
+
requirements: []
|
46
|
+
rubyforge_project:
|
47
|
+
rubygems_version: 1.8.24
|
48
|
+
signing_key:
|
49
|
+
specification_version: 3
|
50
|
+
summary: Google Weather API Wrapper
|
51
|
+
test_files: []
|