technicalpickles-daywalker 0.2.1 → 0.3.1

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/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Josh Nichols
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc CHANGED
@@ -23,10 +23,21 @@ After registering, you will receive an email prompting you to activate the API k
23
23
 
24
24
  Daywalker.api_key = 'this is so sekrit'
25
25
 
26
- pp Daywalker::District.find_by_zip('27511')
27
- pp Daywalker::District.find_by_latlng(40.739157, -73.990929)
28
- pp Daywalker::Legislator.find(:one, :state => 'NY', :district => 4)
29
- pp Daywalker::Legislator.find_all_by_state_and_title('NY', :senator)
26
+ pp Daywalker::District.all_by_zipcode('27511')
27
+
28
+ pp Daywalker::District.unique_by_latitude_and_longitude(40.739157, -73.990929)
29
+
30
+ pp Daywalker::District.unique_by_address('One City Hall Square, Boston, MA 02201')
31
+
32
+ pp Daywalker::Legislator.all_by_zip('02201')
33
+
34
+ pp Daywalker::Legislator.unique(:state => 'NY', :district => 4)
35
+
36
+ pp Daywalker::Legislator.unique_by_state_and_district('NY', 4)
37
+
38
+ pp Daywalker::Legislator.all(:state => 'NY', :title => :senator)
39
+
40
+ pp Daywalker::Legislator.all_by_state_and_title('NY', :senator)
30
41
 
31
42
 
32
43
  == FAQ
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
- :minor: 2
2
+ :minor: 3
3
3
  :patch: 1
4
4
  :major: 0
@@ -53,5 +53,25 @@ module Daywalker
53
53
 
54
54
  unique_by_latitude_and_longitude(location[:latitude], location[:longitude])
55
55
  end
56
+
57
+ def initialize(attributes = {})
58
+ attributes.each do |attribute, value|
59
+ send("#{attribute}=", value)
60
+ end
61
+ end
62
+
63
+ def legislators
64
+ @legislators ||= begin
65
+ representative = Legislator.unique_by_state_and_district(state, number)
66
+ junior_senator = Legislator.unique_by_state_and_district(state, :junior_seat)
67
+ senior_senator = Legislator.unique_by_state_and_district(state, :senior_seat)
68
+
69
+ {
70
+ :representative => representative,
71
+ :junior_senator => junior_senator,
72
+ :senior_senator => senior_senator
73
+ }
74
+ end
75
+ end
56
76
  end
57
77
  end
@@ -192,15 +192,7 @@ module Daywalker
192
192
  def self.all_by_latitude_and_longitude(latitude, longitude)
193
193
  district = District.unique_by_latitude_and_longitude(latitude, longitude)
194
194
 
195
- representative = unique_by_state_and_district(district.state, district.number)
196
- junior_senator = unique_by_state_and_district(district.state, :junior_seat)
197
- senior_senator = unique_by_state_and_district(district.state, :senior_seat)
198
-
199
- {
200
- :representative => representative,
201
- :junior_senator => junior_senator,
202
- :senior_senator => senior_senator
203
- }
195
+ district.legislators
204
196
  end
205
197
 
206
198
  # Find all the legislators serving a specific address. This will include the district's Represenative, the Senior Senator, and the Junior Senator.
@@ -123,5 +123,56 @@ describe Daywalker::District do
123
123
  end
124
124
  end
125
125
  end
126
+
127
+ describe 'legislators' do
128
+ before do
129
+ @district = Daywalker::District.new(:state => 'NY', :number => 21)
130
+
131
+ @representative = mock('representative')
132
+ @junior_senator = mock('junior senator')
133
+ @senior_senator = mock('senior senator')
134
+
135
+ Daywalker::Legislator.stub!(:unique_by_state_and_district).with('NY', 21).and_return(@representative)
136
+ Daywalker::Legislator.stub!(:unique_by_state_and_district).with('NY', :junior_seat).and_return(@junior_senator)
137
+ Daywalker::Legislator.stub!(:unique_by_state_and_district).with('NY', :senior_seat).and_return(@senior_senator)
138
+ end
139
+
140
+ it 'should find the representative for the district' do
141
+ Daywalker::Legislator.should_receive(:unique_by_state_and_district).with('NY', 21).and_return(@representative)
142
+
143
+ @district.legislators
144
+ end
145
+
146
+ it 'should find the junior senator for the state' do
147
+ Daywalker::Legislator.should_receive(:unique_by_state_and_district).with('NY', :junior_seat).and_return(@junior_senator)
148
+
149
+ @district.legislators
150
+ end
151
+
152
+ it 'should find the senior senator for the state' do
153
+ Daywalker::Legislator.should_receive(:unique_by_state_and_district).with('NY', :senior_seat).and_return(@senior_senator)
154
+
155
+ @district.legislators
156
+ end
157
+
158
+ it 'should return the representative, junior senator, and senior senator' do
159
+ @district.legislators.should == {
160
+ :representative => @representative,
161
+ :junior_senator => @junior_senator,
162
+ :senior_senator => @senior_senator
163
+ }
164
+ end
165
+
166
+ it 'should not not attempt to look up if it has been done already' do
167
+ @district.legislators
168
+
169
+ Daywalker::Legislator.should_not_receive(:unique_by_state_and_district).with('NY', :senior_seat).and_return(@senior_senator)
170
+ Daywalker::Legislator.should_not_receive(:unique_by_state_and_district).with('NY', :senior_seat).and_return(@senior_senator)
171
+ Daywalker::Legislator.should_not_receive(:unique_by_state_and_district).with('NY', 21).and_return(@representative)
172
+
173
+ @district.legislators
174
+ end
175
+
176
+ end
126
177
  end
127
178
 
@@ -169,13 +169,16 @@ describe Daywalker::Legislator do
169
169
  @district = mock('district', :state => 'NY', :number => 21)
170
170
  Daywalker::District.stub!(:unique_by_latitude_and_longitude).with(42.731245, -73.684236).and_return(@district)
171
171
 
172
+
172
173
  @representative = mock('representative')
173
174
  @junior_senator = mock('junior senator')
174
175
  @senior_senator = mock('senior senator')
175
176
 
176
- Daywalker::Legislator.stub!(:unique_by_state_and_district).with('NY', 21).and_return(@representative)
177
- Daywalker::Legislator.stub!(:unique_by_state_and_district).with('NY', :junior_seat).and_return(@junior_senator)
178
- Daywalker::Legislator.stub!(:unique_by_state_and_district).with('NY', :senior_seat).and_return(@senior_senator)
177
+ @district.stub!(:legislators).and_return({
178
+ :representative => @representative,
179
+ :junior_senator => @junior_senator,
180
+ :senior_senator => @senior_senator
181
+ })
179
182
  end
180
183
 
181
184
  it 'should find district by lat & lng' do
@@ -184,20 +187,8 @@ describe Daywalker::Legislator do
184
187
  Daywalker::Legislator.all_by_latitude_and_longitude(42.731245, -73.684236)
185
188
  end
186
189
 
187
- it 'should find the representative for the district' do
188
- Daywalker::Legislator.should_receive(:unique_by_state_and_district).with('NY', 21).and_return(@representative)
189
-
190
- Daywalker::Legislator.all_by_latitude_and_longitude(42.731245, -73.684236)
191
- end
192
-
193
- it 'should find the junior senator for the state' do
194
- Daywalker::Legislator.should_receive(:unique_by_state_and_district).with('NY', :junior_seat).and_return(@junior_senator)
195
-
196
- Daywalker::Legislator.all_by_latitude_and_longitude(42.731245, -73.684236)
197
- end
198
-
199
- it 'should find the senior senator for the state' do
200
- Daywalker::Legislator.should_receive(:unique_by_state_and_district).with('NY', :senior_seat).and_return(@senior_senator)
190
+ it 'should find the legislators for the district' do
191
+ @district.should_receive(:legislators)
201
192
 
202
193
  Daywalker::Legislator.all_by_latitude_and_longitude(42.731245, -73.684236)
203
194
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: technicalpickles-daywalker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Josh Nichols
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2009-02-16 00:00:00 -08:00
12
+ date: 2009-03-30 00:00:00 -07:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -48,8 +48,9 @@ executables: []
48
48
 
49
49
  extensions: []
50
50
 
51
- extra_rdoc_files: []
52
-
51
+ extra_rdoc_files:
52
+ - README.rdoc
53
+ - LICENSE
53
54
  files:
54
55
  - README.rdoc
55
56
  - VERSION.yml
@@ -86,6 +87,7 @@ files:
86
87
  - spec/fixtures/legislators_find_one_by_ny_senators.xml
87
88
  - spec/fixtures/rpi_location.yml
88
89
  - spec/spec_helper.rb
90
+ - LICENSE
89
91
  has_rdoc: true
90
92
  homepage: http://github.com/technicalpickles/daywalker
91
93
  post_install_message: