netroots-ruby-votesmart 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
data/VERSION.yml
CHANGED
data/lib/vote_smart/common.rb
CHANGED
@@ -86,7 +86,7 @@ module VoteSmart
|
|
86
86
|
if response.class == Net::HTTPOK
|
87
87
|
result = JSON.parse(response.body)
|
88
88
|
else
|
89
|
-
raise RequestFailed.new("Request was not OK: #{response.class}: #{response.body}")
|
89
|
+
raise RequestFailed.new("Request was not OK: #{response.class}: #{url} #{response.body}")
|
90
90
|
end
|
91
91
|
|
92
92
|
end # self.get_json_data
|
data/lib/vote_smart/official.rb
CHANGED
@@ -5,7 +5,7 @@ module VoteSmart
|
|
5
5
|
attr_accessor :id, :first_name, :nick_name, :middle_name, :last_name, :suffix, :title,
|
6
6
|
:election_parties, :office_parties, :district_id, :district_name, :state_id
|
7
7
|
|
8
|
-
attr_accessor :district, :office
|
8
|
+
attr_accessor :district, :office, :office_id
|
9
9
|
|
10
10
|
set_attribute_map "candidateId" => :id, "firstName" => :first_name, "nickName" => :nick_name,
|
11
11
|
"middleName" => :middle_name, "lastName" => :last_name, "suffix" => :suffix,
|
@@ -20,6 +20,10 @@ module VoteSmart
|
|
20
20
|
"Official: " + [title, first_name, last_name].compact.join(' ')
|
21
21
|
end
|
22
22
|
|
23
|
+
def office_id
|
24
|
+
@office_id || (office.id if office)
|
25
|
+
end
|
26
|
+
|
23
27
|
def self.find_by_district district
|
24
28
|
official = find_by_district_id district.id
|
25
29
|
official.district = district if official
|
@@ -33,13 +37,18 @@ module VoteSmart
|
|
33
37
|
|
34
38
|
def self.find_by_office_id_and_state_id office_id, state_id
|
35
39
|
response = response_child(get_by_office_state(office_id, state_id), "candidateList", "candidate")
|
36
|
-
Official.new(response) unless response.empty?
|
40
|
+
official = Official.new(response) unless response.empty?
|
41
|
+
official.office_id = office_id if official
|
42
|
+
official.state_id ||= state_id if official
|
43
|
+
official
|
37
44
|
end
|
38
45
|
|
39
46
|
|
40
47
|
|
41
48
|
def self.find_all_by_address address, city, state, zip
|
42
49
|
placemark = Geocoding.get("#{address} #{city}, #{state} #{zip}").first
|
50
|
+
state ||= placemark.administrative_area
|
51
|
+
|
43
52
|
placemark ? find_all_by_state_and_latitude_and_longitude(state, placemark.latitude, placemark.longitude) : []
|
44
53
|
end
|
45
54
|
|
@@ -0,0 +1 @@
|
|
1
|
+
{"candidateList":{"generalInfo":{"title":"Project Vote Smart - Search Candidates","linkBack":"http:\/\/votesmart.org\/"},"candidate":{"electionDistrictName":"","lastName":"Suthers","candidateId":"29799","title":"Attorney General","officeDistrictName":"","nickName":"","electionYear":"","electionStatus":"","electionParties":"","middleName":"W.","firstName":"John","electionDistrictId":"","officeParties":"Republican","electionStateId":"","officeStateId":"CO","officeDistrictId":"","suffix":""}}}
|
@@ -9,7 +9,7 @@ module VoteSmart
|
|
9
9
|
Official.find_by_district_id("20451")
|
10
10
|
end
|
11
11
|
|
12
|
-
it_should_find :item => {:last_name => "Isakson", :id => "1721"}
|
12
|
+
it_should_find :item => {:last_name => "Isakson", :id => "1721", :district_id => "20451"}
|
13
13
|
end
|
14
14
|
|
15
15
|
describe "multiple offices" do
|
@@ -33,6 +33,16 @@ module VoteSmart
|
|
33
33
|
it_should_find :count => 1, :first => {:address => {:type => "Capitol"}}
|
34
34
|
end
|
35
35
|
|
36
|
+
describe "find_by_office_id_and_state_id" do
|
37
|
+
|
38
|
+
def do_find
|
39
|
+
Official.find_by_office_id_and_state_id("12", "CO")
|
40
|
+
end
|
41
|
+
|
42
|
+
it_should_find :item => {:last_name => "Suthers", :id => "29799", :office_id => "12", :state_id => "CO"}
|
43
|
+
|
44
|
+
end
|
45
|
+
|
36
46
|
describe "find by address" do
|
37
47
|
|
38
48
|
before :each do
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: netroots-ruby-votesmart
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Dan Cunning
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- spec/responses/Official.get_by_district.20689.js
|
68
68
|
- spec/responses/Official.get_by_district.21397.js
|
69
69
|
- spec/responses/Official.get_by_district.21946.js
|
70
|
+
- spec/responses/Official.get_by_office_state.12.CO.js
|
70
71
|
- spec/responses/Official.get_by_office_state.12.GA.js
|
71
72
|
- spec/responses/Official.get_by_office_state.13.GA.js
|
72
73
|
- spec/responses/Official.get_by_office_state.33.GA.js
|