epa_uv_index 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +17 -0
- data/.rspec +2 -0
- data/Gemfile +10 -0
- data/LICENSE.txt +22 -0
- data/README.md +47 -0
- data/Rakefile +12 -0
- data/epa_uv_index.gemspec +19 -0
- data/lib/epa_uv_index/version.rb +3 -0
- data/lib/epa_uv_index.rb +56 -0
- data/spec/client_spec.rb +206 -0
- data/spec/spec_helper.rb +21 -0
- metadata +58 -0
data/.gitignore
ADDED
data/.rspec
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2012 Greg Gershman
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,47 @@
|
|
1
|
+
# EpaUvIndex
|
2
|
+
|
3
|
+
This is a really simple Ruby client library for accessing the U.S. EPA's UV Index REST API (information here: http://www.epa.gov/enviro/facts/services.html#uvindex)
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
gem 'epa_uv_index'
|
10
|
+
|
11
|
+
And then execute:
|
12
|
+
|
13
|
+
$ bundle
|
14
|
+
|
15
|
+
Or install it yourself as:
|
16
|
+
|
17
|
+
$ gem install epa_uv_index
|
18
|
+
|
19
|
+
## Usage
|
20
|
+
|
21
|
+
Retrieve UV indexes for:
|
22
|
+
|
23
|
+
Hourly, by zip code
|
24
|
+
|
25
|
+
$ EpaUvIndex::Client.hourly_for(:zip => 21209)
|
26
|
+
|
27
|
+
Hourly, by city/state
|
28
|
+
|
29
|
+
$ EpaUvIndex::Client.hourly_for(:city => 'Baltimore', :state => 'md')
|
30
|
+
|
31
|
+
Daily, by zip code
|
32
|
+
|
33
|
+
$ EpaUvIndex::Client.daily_for(:zip => 21209)
|
34
|
+
|
35
|
+
Daily, by city/state
|
36
|
+
|
37
|
+
$ EpaUvIndex::Client.daily_for(:city => 'Baltimore', :state => 'md')
|
38
|
+
|
39
|
+
Missing parameters or bad HTTP responses result in Exceptions being raised.
|
40
|
+
|
41
|
+
## Contributing
|
42
|
+
|
43
|
+
1. Fork it
|
44
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
45
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
46
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
47
|
+
5. Create new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'epa_uv_index/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |gem|
|
7
|
+
gem.name = "epa_uv_index"
|
8
|
+
gem.version = EpaUvIndex::VERSION
|
9
|
+
gem.authors = ["Greg Gershman"]
|
10
|
+
gem.email = ["greg@shelrick.com"]
|
11
|
+
gem.description = %q{Ruby client library for accessing the U.S. EPA's UV Index API (http://www.epa.gov/enviro/facts/services.html#uvindex)'}
|
12
|
+
gem.summary = %q{Get UV Index values by daily and hourly for zip code or city/state}
|
13
|
+
gem.homepage = ""
|
14
|
+
|
15
|
+
gem.files = `git ls-files`.split($/)
|
16
|
+
gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
|
17
|
+
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
|
+
gem.require_paths = ["lib"]
|
19
|
+
end
|
data/lib/epa_uv_index.rb
ADDED
@@ -0,0 +1,56 @@
|
|
1
|
+
require "epa_uv_index/version"
|
2
|
+
require 'httparty'
|
3
|
+
require 'json'
|
4
|
+
|
5
|
+
module EpaUvIndex
|
6
|
+
class Client
|
7
|
+
|
8
|
+
HOURLY_BASE_URL = "http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY"
|
9
|
+
DAILY_BASE_URL = "http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVDAILY"
|
10
|
+
|
11
|
+
def self.hourly_for(params)
|
12
|
+
begin
|
13
|
+
do_request(HOURLY_BASE_URL, params)
|
14
|
+
rescue Exception => e
|
15
|
+
raise e
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.daily_for(params)
|
20
|
+
begin
|
21
|
+
do_request(DAILY_BASE_URL, params)
|
22
|
+
rescue Exception => e
|
23
|
+
raise e
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def self.do_request(base_url, params)
|
30
|
+
raise Exception("Please provide either a city/state or a zip code.") unless params[:zip] or (params[:city] and params[:state])
|
31
|
+
request_url = build_request_url(base_url, params)
|
32
|
+
http_response = HTTParty.get(request_url)
|
33
|
+
begin
|
34
|
+
evaluate_response(http_response)
|
35
|
+
rescue Exception => e
|
36
|
+
raise e
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.build_request_url(base_url, params)
|
41
|
+
if params[:zip]
|
42
|
+
"#{base_url}/ZIP/#{params[:zip]}/json"
|
43
|
+
else
|
44
|
+
"#{base_url}/CITY/#{params[:city]}/STATE/#{params[:state]}/json"
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
def self.evaluate_response(http_response)
|
49
|
+
if http_response.code == 200
|
50
|
+
return JSON.parse(http_response.body)
|
51
|
+
else
|
52
|
+
raise http_response.message
|
53
|
+
end
|
54
|
+
end
|
55
|
+
end
|
56
|
+
end
|
data/spec/client_spec.rb
ADDED
@@ -0,0 +1,206 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe EpaUvIndex::Client do
|
4
|
+
|
5
|
+
describe "#daily_for" do
|
6
|
+
context "when querying for a daily UV index for a zip code" do
|
7
|
+
context "when the response is good" do
|
8
|
+
before do
|
9
|
+
response = mock(Object)
|
10
|
+
response.stub!(:body).and_return '[{"ZIP_CODE":21209,"UV_INDEX":3,"UV_ALERT":0}]'
|
11
|
+
response.stub!(:code).and_return 200
|
12
|
+
HTTParty.should_receive(:get).with("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVDAILY/ZIP/21209/json").and_return response
|
13
|
+
end
|
14
|
+
|
15
|
+
it "should return an array for a daily zip code request" do
|
16
|
+
response = EpaUvIndex::Client.daily_for(:zip => '21209')
|
17
|
+
response.is_a?(Array).should be_true
|
18
|
+
response.first["ZIP_CODE"].should == 21209
|
19
|
+
response.first["UV_INDEX"].should == 3
|
20
|
+
response.first["UV_ALERT"].should == 0
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
context "when the response is empty" do
|
25
|
+
before do
|
26
|
+
response = mock(Object)
|
27
|
+
response.stub!(:body).and_return '[]'
|
28
|
+
response.stub!(:code).and_return 200
|
29
|
+
HTTParty.should_receive(:get).with("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVDAILY/ZIP/21209/json").and_return response
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should return an array for a daily zip code request" do
|
33
|
+
response = EpaUvIndex::Client.daily_for(:zip => '21209')
|
34
|
+
response.is_a?(Array).should be_true
|
35
|
+
response.should be_empty
|
36
|
+
end
|
37
|
+
end
|
38
|
+
|
39
|
+
context "when the status code is not 200" do
|
40
|
+
before do
|
41
|
+
response = mock(Object)
|
42
|
+
response.stub!(:code).and_return 406
|
43
|
+
response.stub!(:message).and_return "Error Message"
|
44
|
+
HTTParty.should_receive(:get).with("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVDAILY/ZIP/21209/json").and_return response
|
45
|
+
end
|
46
|
+
|
47
|
+
it "should raise an exception" do
|
48
|
+
lambda { EpaUvIndex::Client.daily_for(:zip => '21209')}.should raise_error "Error Message"
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
53
|
+
context "when querying for a daily UV index for a city/state" do
|
54
|
+
context "when the response is good" do
|
55
|
+
before do
|
56
|
+
response = mock(Object)
|
57
|
+
response.stub!(:body).and_return '[{"CITY":"BALTIMORE","STATE":"MD","UV_INDEX":4,"UV_ALERT":0}]'
|
58
|
+
response.stub!(:code).and_return 200
|
59
|
+
HTTParty.should_receive(:get).with("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVDAILY/CITY/Baltimore/STATE/md/json").and_return response
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should return an array for a daily zip code request" do
|
63
|
+
response = EpaUvIndex::Client.daily_for(:city => 'Baltimore', :state => 'md')
|
64
|
+
response.is_a?(Array).should be_true
|
65
|
+
response.first["CITY"].should == "BALTIMORE"
|
66
|
+
response.first["STATE"].should == "MD"
|
67
|
+
response.first["UV_INDEX"].should == 4
|
68
|
+
response.first["UV_ALERT"].should == 0
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
context "when the response is empty" do
|
73
|
+
before do
|
74
|
+
response = mock(Object)
|
75
|
+
response.stub!(:body).and_return '[]'
|
76
|
+
response.stub!(:code).and_return 200
|
77
|
+
HTTParty.should_receive(:get).with("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVDAILY/CITY/Baltimore/STATE/md/json").and_return response
|
78
|
+
end
|
79
|
+
|
80
|
+
it "should return an array for a daily zip code request" do
|
81
|
+
response = EpaUvIndex::Client.daily_for(:city => 'Baltimore', :state => 'md')
|
82
|
+
response.is_a?(Array).should be_true
|
83
|
+
response.should be_empty
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
context "when the status code is not 200" do
|
88
|
+
before do
|
89
|
+
response = mock(Object)
|
90
|
+
response.stub!(:code).and_return 406
|
91
|
+
response.stub!(:message).and_return "Error Message"
|
92
|
+
HTTParty.should_receive(:get).with("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVDAILY/CITY/baltimore/STATE/md/json").and_return response
|
93
|
+
end
|
94
|
+
|
95
|
+
it "should raise an exception" do
|
96
|
+
lambda { EpaUvIndex::Client.daily_for(:city => 'baltimore', :state => 'md')}.should raise_error "Error Message"
|
97
|
+
end
|
98
|
+
end
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
102
|
+
describe "#hourly_for" do
|
103
|
+
context "when querying for an hourly UV index for a zip code" do
|
104
|
+
context "when the response is good" do
|
105
|
+
before do
|
106
|
+
response = mock(Object)
|
107
|
+
response.stub!(:body).and_return '[{"ORDER":1,"ZIP":21209,"DATE_TIME":"OCT/09/2012 06 AM","UV_VALUE":0},{"ORDER":2,"ZIP":21209,"DATE_TIME":"OCT/09/2012 07 AM","UV_VALUE":0},{"ORDER":3,"ZIP":21209,"DATE_TIME":"OCT/09/2012 08 AM","UV_VALUE":0},{"ORDER":4,"ZIP":21209,"DATE_TIME":"OCT/09/2012 09 AM","UV_VALUE":0},{"ORDER":5,"ZIP":21209,"DATE_TIME":"OCT/09/2012 10 AM","UV_VALUE":2},{"ORDER":6,"ZIP":21209,"DATE_TIME":"OCT/09/2012 11 AM","UV_VALUE":1},{"ORDER":7,"ZIP":21209,"DATE_TIME":"OCT/09/2012 12 PM","UV_VALUE":2},{"ORDER":8,"ZIP":21209,"DATE_TIME":"OCT/09/2012 01 PM","UV_VALUE":2},{"ORDER":9,"ZIP":21209,"DATE_TIME":"OCT/09/2012 02 PM","UV_VALUE":1},{"ORDER":10,"ZIP":21209,"DATE_TIME":"OCT/09/2012 03 PM","UV_VALUE":1},{"ORDER":11,"ZIP":21209,"DATE_TIME":"OCT/09/2012 04 PM","UV_VALUE":0},{"ORDER":12,"ZIP":21209,"DATE_TIME":"OCT/09/2012 05 PM","UV_VALUE":0},{"ORDER":13,"ZIP":21209,"DATE_TIME":"OCT/09/2012 06 PM","UV_VALUE":0},{"ORDER":14,"ZIP":21209,"DATE_TIME":"OCT/09/2012 07 PM","UV_VALUE":0},{"ORDER":15,"ZIP":21209,"DATE_TIME":"OCT/09/2012 08 PM","UV_VALUE":0},{"ORDER":16,"ZIP":21209,"DATE_TIME":"OCT/09/2012 09 PM","UV_VALUE":0},{"ORDER":17,"ZIP":21209,"DATE_TIME":"OCT/09/2012 10 PM","UV_VALUE":0},{"ORDER":18,"ZIP":21209,"DATE_TIME":"OCT/09/2012 11 PM","UV_VALUE":0},{"ORDER":19,"ZIP":21209,"DATE_TIME":"OCT/09/2012 12 AM","UV_VALUE":0},{"ORDER":20,"ZIP":21209,"DATE_TIME":"OCT/09/2012 01 AM","UV_VALUE":0},{"ORDER":21,"ZIP":21209,"DATE_TIME":"OCT/09/2012 02 AM","UV_VALUE":0}]'
|
108
|
+
response.stub!(:code).and_return 200
|
109
|
+
HTTParty.should_receive(:get).with("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/ZIP/21209/json").and_return response
|
110
|
+
end
|
111
|
+
|
112
|
+
it "should return an array for a daily zip code request" do
|
113
|
+
response = EpaUvIndex::Client.hourly_for(:zip => '21209')
|
114
|
+
response.is_a?(Array).should be_true
|
115
|
+
response.size.should == 21
|
116
|
+
response.each_with_index do |value, index|
|
117
|
+
value["ORDER"].should == index + 1
|
118
|
+
value["ZIP"].should == 21209
|
119
|
+
value["DATE_TIME"].should =~ /OCT\/09\/2012/
|
120
|
+
value["UV_VALUE"].is_a?(Integer).should be_true
|
121
|
+
end
|
122
|
+
end
|
123
|
+
end
|
124
|
+
|
125
|
+
context "when the response is empty" do
|
126
|
+
before do
|
127
|
+
response = mock(Object)
|
128
|
+
response.stub!(:body).and_return '[]'
|
129
|
+
response.stub!(:code).and_return 200
|
130
|
+
HTTParty.should_receive(:get).with("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/ZIP/21209/json").and_return response
|
131
|
+
end
|
132
|
+
|
133
|
+
it "should return an array for a daily zip code request" do
|
134
|
+
response = EpaUvIndex::Client.hourly_for(:zip => '21209')
|
135
|
+
response.is_a?(Array).should be_true
|
136
|
+
response.should be_empty
|
137
|
+
end
|
138
|
+
end
|
139
|
+
|
140
|
+
context "when the status code is not 200" do
|
141
|
+
before do
|
142
|
+
response = mock(Object)
|
143
|
+
response.stub!(:code).and_return 406
|
144
|
+
response.stub!(:message).and_return "Error Message"
|
145
|
+
HTTParty.should_receive(:get).with("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/ZIP/21209/json").and_return response
|
146
|
+
end
|
147
|
+
|
148
|
+
it "should raise an exception" do
|
149
|
+
lambda { EpaUvIndex::Client.hourly_for(:zip => '21209')}.should raise_error "Error Message"
|
150
|
+
end
|
151
|
+
end
|
152
|
+
end
|
153
|
+
|
154
|
+
context "when query for an hourly UV index for a city/state" do
|
155
|
+
context "when the response is good" do
|
156
|
+
before do
|
157
|
+
response = mock(Object)
|
158
|
+
response.stub!(:body).and_return '[{"SEQUENCE":1,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 06 AM","UV_VALUE":0},{"SEQUENCE":2,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 07 AM","UV_VALUE":0},{"SEQUENCE":3,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 08 AM","UV_VALUE":0},{"SEQUENCE":4,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 09 AM","UV_VALUE":0},{"SEQUENCE":5,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 10 AM","UV_VALUE":1},{"SEQUENCE":6,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 11 AM","UV_VALUE":1},{"SEQUENCE":7,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 12 PM","UV_VALUE":2},{"SEQUENCE":8,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 01 PM","UV_VALUE":2},{"SEQUENCE":9,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 02 PM","UV_VALUE":1},{"SEQUENCE":10,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 03 PM","UV_VALUE":1},{"SEQUENCE":11,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 04 PM","UV_VALUE":0},{"SEQUENCE":12,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 05 PM","UV_VALUE":0},{"SEQUENCE":13,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 06 PM","UV_VALUE":0},{"SEQUENCE":14,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 07 PM","UV_VALUE":0},{"SEQUENCE":15,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 08 PM","UV_VALUE":0},{"SEQUENCE":16,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 09 PM","UV_VALUE":0},{"SEQUENCE":17,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 10 PM","UV_VALUE":0},{"SEQUENCE":18,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 11 PM","UV_VALUE":0},{"SEQUENCE":19,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 12 AM","UV_VALUE":0},{"SEQUENCE":20,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 01 AM","UV_VALUE":0},{"SEQUENCE":21,"CITY":"BALTIMORE","STATE":"MD","DATE_TIME":"OCT/09/2012 02 AM","UV_VALUE":0}]'
|
159
|
+
response.stub!(:code).and_return 200
|
160
|
+
HTTParty.should_receive(:get).with("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/CITY/Baltimore/STATE/md/json").and_return response
|
161
|
+
end
|
162
|
+
|
163
|
+
it "should return an array for a daily zip code request" do
|
164
|
+
response = EpaUvIndex::Client.hourly_for(:city => 'Baltimore', :state => 'md')
|
165
|
+
response.is_a?(Array).should be_true
|
166
|
+
response.size.should == 21
|
167
|
+
response.each_with_index do |value, index|
|
168
|
+
value["SEQUENCE"].should == index + 1
|
169
|
+
value["CITY"].should == "BALTIMORE"
|
170
|
+
value["STATE"].should == "MD"
|
171
|
+
value["DATE_TIME"].should =~ /OCT\/09\/2012/
|
172
|
+
value["UV_VALUE"].is_a?(Integer).should be_true
|
173
|
+
end
|
174
|
+
end
|
175
|
+
end
|
176
|
+
|
177
|
+
context "when the response is empty" do
|
178
|
+
before do
|
179
|
+
response = mock(Object)
|
180
|
+
response.stub!(:body).and_return '[]'
|
181
|
+
response.stub!(:code).and_return 200
|
182
|
+
HTTParty.should_receive(:get).with("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/CITY/Baltimore/STATE/md/json").and_return response
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should return an array for a daily zip code request" do
|
186
|
+
response = EpaUvIndex::Client.hourly_for(:city => 'Baltimore', :state => 'md')
|
187
|
+
response.is_a?(Array).should be_true
|
188
|
+
response.should be_empty
|
189
|
+
end
|
190
|
+
end
|
191
|
+
|
192
|
+
context "when the status code is not 200" do
|
193
|
+
before do
|
194
|
+
response = mock(Object)
|
195
|
+
response.stub!(:code).and_return 406
|
196
|
+
response.stub!(:message).and_return "Error Message"
|
197
|
+
HTTParty.should_receive(:get).with("http://iaspub.epa.gov/enviro/efservice/getEnvirofactsUVHOURLY/CITY/baltimore/STATE/md/json").and_return response
|
198
|
+
end
|
199
|
+
|
200
|
+
it "should raise an exception" do
|
201
|
+
lambda { EpaUvIndex::Client.hourly_for(:city => 'baltimore', :state => 'md')}.should raise_error "Error Message"
|
202
|
+
end
|
203
|
+
end
|
204
|
+
end
|
205
|
+
end
|
206
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
4
|
+
# loaded once.
|
5
|
+
#
|
6
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
|
+
require 'rubygems'
|
8
|
+
require 'bundler/setup'
|
9
|
+
require 'epa_uv_index'
|
10
|
+
|
11
|
+
RSpec.configure do |config|
|
12
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
13
|
+
config.run_all_when_everything_filtered = true
|
14
|
+
config.filter_run :focus
|
15
|
+
|
16
|
+
# Run specs in random order to surface order dependencies. If you find an
|
17
|
+
# order dependency and want to debug it, you can fix the order by providing
|
18
|
+
# the seed, which is printed after each run.
|
19
|
+
# --seed 1234
|
20
|
+
config.order = 'random'
|
21
|
+
end
|
metadata
ADDED
@@ -0,0 +1,58 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: epa_uv_index
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Greg Gershman
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2012-10-10 00:00:00.000000000 Z
|
13
|
+
dependencies: []
|
14
|
+
description: Ruby client library for accessing the U.S. EPA's UV Index API (http://www.epa.gov/enviro/facts/services.html#uvindex)'
|
15
|
+
email:
|
16
|
+
- greg@shelrick.com
|
17
|
+
executables: []
|
18
|
+
extensions: []
|
19
|
+
extra_rdoc_files: []
|
20
|
+
files:
|
21
|
+
- .gitignore
|
22
|
+
- .rspec
|
23
|
+
- Gemfile
|
24
|
+
- LICENSE.txt
|
25
|
+
- README.md
|
26
|
+
- Rakefile
|
27
|
+
- epa_uv_index.gemspec
|
28
|
+
- lib/epa_uv_index.rb
|
29
|
+
- lib/epa_uv_index/version.rb
|
30
|
+
- spec/client_spec.rb
|
31
|
+
- spec/spec_helper.rb
|
32
|
+
homepage: ''
|
33
|
+
licenses: []
|
34
|
+
post_install_message:
|
35
|
+
rdoc_options: []
|
36
|
+
require_paths:
|
37
|
+
- lib
|
38
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
39
|
+
none: false
|
40
|
+
requirements:
|
41
|
+
- - ! '>='
|
42
|
+
- !ruby/object:Gem::Version
|
43
|
+
version: '0'
|
44
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
45
|
+
none: false
|
46
|
+
requirements:
|
47
|
+
- - ! '>='
|
48
|
+
- !ruby/object:Gem::Version
|
49
|
+
version: '0'
|
50
|
+
requirements: []
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.8.24
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: Get UV Index values by daily and hourly for zip code or city/state
|
56
|
+
test_files:
|
57
|
+
- spec/client_spec.rb
|
58
|
+
- spec/spec_helper.rb
|