current_weather 0.0.3 → 0.0.4
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +14 -2
- data/current_weather.gemspec +1 -0
- data/lib/current_weather/todays_weather.rb +13 -9
- data/lib/current_weather/version.rb +1 -1
- data/spec/client_spec.rb +9 -0
- data/spec/fixtures/sample_chicago_response.xml +1 -0
- data/spec/spec_helper.rb +2 -0
- data/spec/todays_weather_spec.rb +21 -0
- metadata +26 -7
data/README.md
CHANGED
@@ -1,6 +1,11 @@
|
|
1
1
|
# Weather
|
2
2
|
|
3
|
-
|
3
|
+
A dead freakin' simple weather gem. No frills or side of guac included. Use this gem to get the following information:
|
4
|
+
* Condition (i.e. 'partly cloudy')
|
5
|
+
* Temperature (Fahrenheit only - c'mon this is the USA we don't do the whole metric system thing)
|
6
|
+
* Humidity (percentage)
|
7
|
+
* Icon (.gif image that corresponds to the condition)
|
8
|
+
* Wind Condition (i.e. 'N at 9 mph')
|
4
9
|
|
5
10
|
## Installation
|
6
11
|
|
@@ -18,7 +23,14 @@ Or install it yourself as:
|
|
18
23
|
|
19
24
|
## Usage
|
20
25
|
|
21
|
-
|
26
|
+
Gem has only one class level method to interact with and returns an instance of the TodaysWeather class.
|
27
|
+
#### Example Call
|
28
|
+
WeatherApi::TodaysWeather.find('Chicago') #=> returns the following attributes
|
29
|
+
* condition
|
30
|
+
* temperature
|
31
|
+
* humidity
|
32
|
+
* icon
|
33
|
+
* wind_condition
|
22
34
|
|
23
35
|
## Contributing
|
24
36
|
|
data/current_weather.gemspec
CHANGED
@@ -2,23 +2,27 @@ require 'nokogiri'
|
|
2
2
|
|
3
3
|
module WeatherApi
|
4
4
|
class TodaysWeather
|
5
|
-
attr_accessor :condition, :temperature, :humidity, :icon, :
|
5
|
+
attr_accessor :condition, :temperature, :humidity, :icon, :wind_condition
|
6
|
+
|
7
|
+
def initialize(attributes)
|
8
|
+
self.condition = attributes['condition'].first
|
9
|
+
self.temperature = attributes['temp_f'].first
|
10
|
+
self.humidity = attributes['humidity'].first
|
11
|
+
self.icon = "www.google.com" + attributes['icon'].first
|
12
|
+
self.wind_condition = attributes['wind_condition'].first
|
13
|
+
end
|
6
14
|
|
7
15
|
def self.client
|
8
16
|
WeatherApi::Client.new
|
9
17
|
end
|
10
18
|
|
11
|
-
def
|
12
|
-
|
13
|
-
self.temperature = attributes['temp_f'].first
|
14
|
-
self.humidity = attributes['humidity'].first
|
15
|
-
self.icon = "www.google.com" + attributes['icon'].first
|
16
|
-
self.wind_conditon = attributes['wind_condition'].first
|
19
|
+
def self.parse(xml_package)
|
20
|
+
Nokogiri::HTML(xml_package)
|
17
21
|
end
|
18
22
|
|
19
|
-
def self.
|
23
|
+
def self.find(location)
|
20
24
|
attributes_hash = Hash.new
|
21
|
-
response =
|
25
|
+
response = parse(client.get_weather(location))
|
22
26
|
response.css('current_conditions').each do |stat|
|
23
27
|
stat.children.each do |key|
|
24
28
|
attributes_hash[key.name] = key.values { |value| value }
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
<?xml version="1.0"?><xml_api_reply version="1"><weather module_id="0" tab_id="0" mobile_row="0" mobile_zipped="1" row="0" section="0" ><forecast_information><city data="Chicago, IL"/><postal_code data="chicago"/><latitude_e6 data=""/><longitude_e6 data=""/><forecast_date data="2012-07-08"/><current_date_time data="2012-07-09 03:51:00 +0000"/><unit_system data="US"/></forecast_information><current_conditions><condition data="Partly Cloudy"/><temp_f data="75"/><temp_c data="24"/><humidity data="Humidity: 48%"/><icon data="/ig/images/weather/partly_cloudy.gif"/><wind_condition data="Wind: NE at 6 mph"/></current_conditions><forecast_conditions><day_of_week data="Sun"/><low data="70"/><high data="81"/><icon data="/ig/images/weather/mostly_sunny.gif"/><condition data="Mostly Sunny"/></forecast_conditions><forecast_conditions><day_of_week data="Mon"/><low data="73"/><high data="82"/><icon data="/ig/images/weather/mostly_sunny.gif"/><condition data="Mostly Sunny"/></forecast_conditions><forecast_conditions><day_of_week data="Tue"/><low data="72"/><high data="81"/><icon data="/ig/images/weather/sunny.gif"/><condition data="Clear"/></forecast_conditions><forecast_conditions><day_of_week data="Wed"/><low data="77"/><high data="82"/><icon data="/ig/images/weather/mostly_sunny.gif"/><condition data="Mostly Sunny"/></forecast_conditions></weather></xml_api_reply>
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe WeatherApi::TodaysWeather do
|
4
|
+
let(:sample_response) { File.open("spec/fixtures/sample_chicago_response.xml") }
|
5
|
+
|
6
|
+
before(:each) do
|
7
|
+
WeatherApi::TodaysWeather.stub(:parse).and_return(Nokogiri::HTML(sample_response))
|
8
|
+
end
|
9
|
+
|
10
|
+
describe ".find(location)" do
|
11
|
+
it "returns an instance of WeatherApi::TodaysWeather" do
|
12
|
+
WeatherApi::TodaysWeather.find('Chicago').should be_a(WeatherApi::TodaysWeather)
|
13
|
+
end
|
14
|
+
|
15
|
+
context "verifying the data was set correctly" do
|
16
|
+
it 'returns a valid temperature' do
|
17
|
+
WeatherApi::TodaysWeather.find("Chicago").temperature.should == "75"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: current_weather
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.4
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-07-09 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: faraday
|
16
|
-
requirement: &
|
16
|
+
requirement: &70268434372680 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *70268434372680
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: nokogiri
|
27
|
-
requirement: &
|
27
|
+
requirement: &70268434370800 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,7 +32,18 @@ dependencies:
|
|
32
32
|
version: '0'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *70268434370800
|
36
|
+
- !ruby/object:Gem::Dependency
|
37
|
+
name: rspec
|
38
|
+
requirement: &70268434368660 !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
type: :development
|
45
|
+
prerelease: false
|
46
|
+
version_requirements: *70268434368660
|
36
47
|
description: google weather wrapper for ruby
|
37
48
|
email:
|
38
49
|
- michael.v.verdi@gmail.com
|
@@ -53,6 +64,10 @@ files:
|
|
53
64
|
- lib/current_weather/client.rb
|
54
65
|
- lib/current_weather/todays_weather.rb
|
55
66
|
- lib/current_weather/version.rb
|
67
|
+
- spec/client_spec.rb
|
68
|
+
- spec/fixtures/sample_chicago_response.xml
|
69
|
+
- spec/spec_helper.rb
|
70
|
+
- spec/todays_weather_spec.rb
|
56
71
|
homepage: ''
|
57
72
|
licenses: []
|
58
73
|
post_install_message:
|
@@ -77,4 +92,8 @@ rubygems_version: 1.8.17
|
|
77
92
|
signing_key:
|
78
93
|
specification_version: 3
|
79
94
|
summary: google weather wrapper for ruby
|
80
|
-
test_files:
|
95
|
+
test_files:
|
96
|
+
- spec/client_spec.rb
|
97
|
+
- spec/fixtures/sample_chicago_response.xml
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
- spec/todays_weather_spec.rb
|