netroots-ruby-votesmart 0.1.1 → 0.2.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/History.txt +4 -0
- data/README.rdoc +48 -0
- data/VERSION.yml +4 -0
- data/lib/mcll4r/MIT-LICENSE +20 -0
- data/lib/mcll4r/README +19 -0
- data/lib/mcll4r/mcll4r.rb +24 -0
- data/lib/mcll4r/mcll4r_test.rb +35 -0
- data/lib/ruby-votesmart.rb +22 -0
- data/lib/vote_smart/address.rb +42 -0
- data/lib/vote_smart/candidate.rb +32 -0
- data/lib/vote_smart/candidate_bio.rb +16 -0
- data/lib/vote_smart/candidate_office.rb +15 -0
- data/lib/vote_smart/committee.rb +23 -0
- data/lib/vote_smart/common.rb +91 -0
- data/lib/vote_smart/district.rb +36 -0
- data/lib/vote_smart/election.rb +21 -0
- data/lib/vote_smart/leadership.rb +16 -0
- data/lib/vote_smart/local.rb +21 -0
- data/lib/vote_smart/measure.rb +16 -0
- data/lib/vote_smart/notes.rb +11 -0
- data/lib/vote_smart/npat.rb +11 -0
- data/lib/vote_smart/office.rb +113 -0
- data/lib/vote_smart/official.rb +111 -0
- data/lib/vote_smart/phone.rb +12 -0
- data/lib/vote_smart/rating.rb +26 -0
- data/lib/vote_smart/state.rb +29 -0
- data/lib/vote_smart/vote.rb +70 -0
- data/spec/responses/Address.get_office.1721.js +1 -0
- data/spec/responses/District.get_by_office_state.7.GA.js +1 -0
- data/spec/responses/District.get_by_office_state.8.GA.js +1 -0
- data/spec/responses/District.get_by_office_state.9.GA.js +1 -0
- data/spec/responses/Office.get_offices_by_type.C.js +1 -0
- data/spec/responses/Office.get_offices_by_type.L.js +1 -0
- data/spec/responses/Office.get_offices_by_type.P.js +1 -0
- data/spec/responses/Office.get_offices_by_type.S.js +1 -0
- data/spec/responses/Office.get_types.js +1 -0
- data/spec/responses/Official.get_by_district.20451.js +1 -0
- data/spec/responses/Official.get_by_district.20689.js +1 -0
- data/spec/responses/Official.get_by_district.21946.js +1 -0
- data/spec/responses/Official.get_by_office_state.12.GA.js +1 -0
- data/spec/responses/Official.get_by_office_state.13.GA.js +1 -0
- data/spec/responses/Official.get_by_office_state.33.GA.js +1 -0
- data/spec/responses/Official.get_by_office_state.42.GA.js +1 -0
- data/spec/responses/Official.get_by_office_state.44.GA.js +1 -0
- data/spec/responses/Official.get_by_office_state.45.GA.js +1 -0
- data/spec/responses/Official.get_by_office_state.53.GA.js +1 -0
- data/spec/responses/State.get_state.GA.js +1 -0
- data/spec/responses/State.get_state_ids.js +1 -0
- data/spec/responses/authorization_failed.js +1 -0
- data/spec/spec_helper.rb +98 -0
- data/spec/vote_smart/district_spec.rb +36 -0
- data/spec/vote_smart/office_spec.rb +96 -0
- data/spec/vote_smart/official_spec.rb +44 -0
- data/spec/vote_smart/state_spec.rb +28 -0
- metadata +68 -29
@@ -0,0 +1,21 @@
|
|
1
|
+
module VoteSmart
|
2
|
+
|
3
|
+
class Election < Common
|
4
|
+
|
5
|
+
# Returns detailed election information
|
6
|
+
def self.get_election election_id
|
7
|
+
request("Election.getElection", "electionId" => election_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
# returns a list of elections based on the criteria
|
11
|
+
def self.get_election_by_year_state year, state_id
|
12
|
+
request("Election.getElectionByYearState", "year" => year, "stateId" => state_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a list of candidates in the election and election stage provided
|
16
|
+
def self.get_stage_candidates election_id, stage_id, party = ""
|
17
|
+
request("Election.getStageCandidates", "electionId" => election_id, "stageId" => stage_id, "party" => party)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VoteSmart
|
2
|
+
|
3
|
+
class Leadership < Common
|
4
|
+
|
5
|
+
# Returns a list of leadership positions
|
6
|
+
def self.get_positions state_id = "NA", office_id = nil
|
7
|
+
request("Leadership.getPositions", "stateId" => state_id, "officeId" => office_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns a list of candidates in specific leadership positions
|
11
|
+
def self.get_officials leadership_id, state_id = "NA"
|
12
|
+
request("Leadership.getOfficials", "leadershipId" => leadership_id, "stateId" => state_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module VoteSmart
|
2
|
+
|
3
|
+
class Local < Common
|
4
|
+
|
5
|
+
# Returns a list of cities in a given state
|
6
|
+
def get_cities state_id
|
7
|
+
request("Local.getCities", "stateId" => state_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns a list of counties in a given state.
|
11
|
+
def get_counties state_id
|
12
|
+
request("Local.getCounties", "stateId" => state_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
#
|
16
|
+
def get_officials local_id
|
17
|
+
request("Local.getOfficials", "localId" => local_id)
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module VoteSmart
|
2
|
+
|
3
|
+
class Measure < Common
|
4
|
+
|
5
|
+
# Returns a ballot measure's details
|
6
|
+
def self.get_measure measure_id
|
7
|
+
request("Measure.getMeasure", "measureId" => measure_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns a list of ballot measures that fit the criteria
|
11
|
+
def self.get_measures_by_year_state year, state_id
|
12
|
+
request("Measure.getMeasuresByYearState", "year" => year, "stateId" => state_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
@@ -0,0 +1,113 @@
|
|
1
|
+
module VoteSmart
|
2
|
+
|
3
|
+
class Office < Common
|
4
|
+
|
5
|
+
attr_accessor :id, :type_id, :level_id, :branch_id, :name, :title, :short_title
|
6
|
+
|
7
|
+
set_attribute_map "officeId" => :id, "officeTypeId" => :type_id, "officeLevelId" => :level_id,
|
8
|
+
"officeBranchId" => :branch_id, "name" => :name, "title" => :title, "shortTitle" => :short_title
|
9
|
+
|
10
|
+
def districts_by_state_id state_id
|
11
|
+
@districts_by_state ||= {}
|
12
|
+
@districts_by_state[state_id] ||= District.find_all_by_office_id_and_state_id(self.id, state_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
def district_by_state_id_and_number state_id, number
|
16
|
+
number = number.to_i
|
17
|
+
districts = districts_by_state_id(state_id)
|
18
|
+
districts.find {|district| district.number == number}
|
19
|
+
end
|
20
|
+
|
21
|
+
def official_by_state_id state_id
|
22
|
+
@official_by_state ||= {}
|
23
|
+
@official_by_state[state_id] ||= Official.find_by_office_id_and_state_id(self.id, state_id)
|
24
|
+
end
|
25
|
+
|
26
|
+
def self.all
|
27
|
+
Type.all.collect { |type| find_all_by_type(type) }.uniq.flatten
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.find_all_by_type type
|
31
|
+
find_all_by_type_id(type.id)
|
32
|
+
end
|
33
|
+
|
34
|
+
def self.find_all_by_type_id type_id
|
35
|
+
response_child(get_offices_by_type(type_id), "offices", "office").collect {|attributes| Office.new(attributes)}
|
36
|
+
end
|
37
|
+
|
38
|
+
def self.find_by_name name
|
39
|
+
Office.all.collect {|office| office if office.name == name }.compact.first
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.find_all_by_name names
|
43
|
+
offices = Office.all
|
44
|
+
names.collect {|name| offices.find {|office| office.name == name }}
|
45
|
+
end
|
46
|
+
|
47
|
+
# Gets a list of office types
|
48
|
+
def self.get_types
|
49
|
+
request("Office.getTypes")
|
50
|
+
end
|
51
|
+
|
52
|
+
# Returns branches of government and their respective IDs
|
53
|
+
def self.get_branches
|
54
|
+
request("Office.getBranches")
|
55
|
+
end
|
56
|
+
|
57
|
+
# Returns levels of government and their respective IDs
|
58
|
+
def self.get_levels
|
59
|
+
request("Office.getLevels")
|
60
|
+
end
|
61
|
+
|
62
|
+
# Returns a list of offices by office type
|
63
|
+
def self.get_offices_by_type type_id
|
64
|
+
request("Office.getOfficesByType", "typeId" => type_id)
|
65
|
+
end
|
66
|
+
|
67
|
+
# Returns a list of offices by level of government
|
68
|
+
def self.get_offices_by_level level_id
|
69
|
+
request("Office.getOfficesByLevel", "levelId" => level_id)
|
70
|
+
end
|
71
|
+
|
72
|
+
# Returns a list of offices by office type and level of government
|
73
|
+
def self.get_offices_by_type_level type_id, level_id
|
74
|
+
request("Office.getOfficesByType", "levelId" => level_id, "typeId" => type_id)
|
75
|
+
end
|
76
|
+
|
77
|
+
# Returns a list of offices by branch and level of government
|
78
|
+
def self.get_offices_by_branch_level branch_id, level_id
|
79
|
+
request("Office.getOfficesByBranchLevel", "branchId" => branch_id, "levelId" => level_id)
|
80
|
+
end
|
81
|
+
|
82
|
+
class Type < Common
|
83
|
+
|
84
|
+
|
85
|
+
attr_accessor :id, :level_id, :branch_id, :name
|
86
|
+
|
87
|
+
set_attribute_map "officeTypeId" => :id, "officeLevelId" => :level_id,
|
88
|
+
"officeBranchId" => :branch_id, "name" => :name
|
89
|
+
|
90
|
+
def self.all
|
91
|
+
@types ||= response_child(Office.get_types, "officeTypes", "type").collect {|attributes| Type.new(attributes)}
|
92
|
+
end
|
93
|
+
|
94
|
+
def self.find_by_name name
|
95
|
+
Type.all.collect {|type| type if type.name == name }.compact.first
|
96
|
+
end
|
97
|
+
|
98
|
+
def offices
|
99
|
+
@offices ||= Office.find_all_by_type(self)
|
100
|
+
end
|
101
|
+
|
102
|
+
def offices_by_name names
|
103
|
+
names.collect {|name| offices.find {|office| office.name == name }}
|
104
|
+
end
|
105
|
+
|
106
|
+
def office_by_name name
|
107
|
+
offices_by_name([name]).first
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
|
112
|
+
end
|
113
|
+
end
|
@@ -0,0 +1,111 @@
|
|
1
|
+
module VoteSmart
|
2
|
+
|
3
|
+
class Official < Common
|
4
|
+
|
5
|
+
attr_accessor :id, :first_name, :nick_name, :middle_name, :last_name, :suffix, :title,
|
6
|
+
:election_parties, :office_parties, :district_id, :district_name, :state_id
|
7
|
+
|
8
|
+
set_attribute_map "candidateId" => :id, "firstName" => :first_name, "nickName" => :nick_name,
|
9
|
+
"middleName" => :middle_name, "lastName" => :last_name, "suffix" => :suffix,
|
10
|
+
"title" => :title, "electionParties" => :election_parties, "officeDistrictId" => :district_id,
|
11
|
+
"officeDistrictName" => :district_name, "officeStateId" => :state_id
|
12
|
+
|
13
|
+
def offices
|
14
|
+
Official.response_child(Address.get_office(self.id), "address", "office").collect {|office| CandidateOffice.new(office) }
|
15
|
+
end
|
16
|
+
|
17
|
+
def inspect
|
18
|
+
"Official: " + [title, first_name, last_name].compact.join(' ')
|
19
|
+
end
|
20
|
+
|
21
|
+
def self.find_by_district district
|
22
|
+
find_by_district_id district.id
|
23
|
+
end
|
24
|
+
|
25
|
+
def self.find_by_district_id district_id
|
26
|
+
response = response_child(get_by_district(district_id), "candidateList", "candidate")
|
27
|
+
Official.new(response) unless response.empty?
|
28
|
+
end
|
29
|
+
|
30
|
+
def self.find_by_office_id_and_state_id office_id, state_id
|
31
|
+
response = response_child(get_by_office_state(office_id, state_id), "candidateList", "candidate")
|
32
|
+
Official.new(response) unless response.empty?
|
33
|
+
end
|
34
|
+
|
35
|
+
|
36
|
+
|
37
|
+
def self.find_all_by_address address, city, state, zip
|
38
|
+
placemark = Geocoding.get("#{address} #{city}, #{state} #{zip}").first
|
39
|
+
placemark ? find_all_by_state_and_latitude_and_longitude(state, placemark.latitude, placemark.longitude) : []
|
40
|
+
end
|
41
|
+
|
42
|
+
def self.find_all_by_state_and_latitude_and_longitude state, latitude, longitude
|
43
|
+
response = Mcll4r.new.district_lookup(latitude, longitude)
|
44
|
+
response = response["response"] if response
|
45
|
+
|
46
|
+
state_upper = (response["state_upper"] || {})["district"]
|
47
|
+
state_lower = (response["state_lower"] || {})["district"]
|
48
|
+
|
49
|
+
find_all_state_wide_officials(state) + find_state_legislators(state, state_upper, state_lower, state_lower)
|
50
|
+
end
|
51
|
+
|
52
|
+
def self.find_all_state_wide_officials state_id
|
53
|
+
state_wide_office_names = ["Secretary of State", "Secretary of the Commonwealth", "Attorney General", "Secretary of Education",
|
54
|
+
"Education Secretary", "Treasurer", "Auditor"]
|
55
|
+
|
56
|
+
state_wide_type = Office::Type.find_by_name("State Wide")
|
57
|
+
|
58
|
+
state_wide_offices = state_wide_type ? state_wide_type.offices_by_name(state_wide_office_names) : []
|
59
|
+
|
60
|
+
state_wide_offices.collect { |office| office.official_by_state_id(state_id) }.compact
|
61
|
+
end
|
62
|
+
|
63
|
+
def self.find_state_legislators state_id, senate_district, house_district, assembly_district
|
64
|
+
officials = []
|
65
|
+
|
66
|
+
state_leg_type = Office::Type.find_by_name("State Legislature")
|
67
|
+
|
68
|
+
{"State Senate" => senate_district,
|
69
|
+
"State House" => house_district,
|
70
|
+
"State Assembly" => assembly_district}.each do |office_name, district_number|
|
71
|
+
|
72
|
+
office = state_leg_type.office_by_name(office_name) if state_leg_type
|
73
|
+
|
74
|
+
district = office.district_by_state_id_and_number(state_id, district_number) if office
|
75
|
+
|
76
|
+
official = district.official if district
|
77
|
+
|
78
|
+
officials.push official if official
|
79
|
+
end
|
80
|
+
|
81
|
+
officials
|
82
|
+
end
|
83
|
+
|
84
|
+
|
85
|
+
# Returns a list of incumbents that fit the criteria
|
86
|
+
def self.get_by_office_state office_id, state_id = 'NA'
|
87
|
+
request("Officials.getByOfficeState", "officeId" => office_id, "stateId" => state_id)
|
88
|
+
end
|
89
|
+
|
90
|
+
# Searches for incumbents with exact lastname matches
|
91
|
+
def self.get_by_lastname lastname
|
92
|
+
request("Officials.getByLastname", "lastName" => lastname)
|
93
|
+
end
|
94
|
+
|
95
|
+
# Searches for incumbents with fuzzy lastname match
|
96
|
+
def self.get_by_levenstein lastname
|
97
|
+
request("Officials.getByLevenstein", "lastName" => lastname)
|
98
|
+
end
|
99
|
+
|
100
|
+
# Returns incumbents in the provided election_id
|
101
|
+
def self.get_by_election election_id
|
102
|
+
request("Officials.getByElection", "electionId" => election_id)
|
103
|
+
end
|
104
|
+
|
105
|
+
# Returns incumbents in the provided district_id
|
106
|
+
def self.get_by_district district_id
|
107
|
+
request("Officials.getByDistrict", "districtId" => district_id)
|
108
|
+
end
|
109
|
+
|
110
|
+
end
|
111
|
+
end
|
@@ -0,0 +1,12 @@
|
|
1
|
+
module VoteSmart
|
2
|
+
|
3
|
+
class Phone < Common
|
4
|
+
|
5
|
+
attr_accessor :phone1, :phone2, :fax1, :fax2, :toll_free, :ttyd
|
6
|
+
|
7
|
+
set_attribute_map "phone1" => :phone1, "phone2" => :phone2, "fax1" => :fax1, "fax2" => :fax2,
|
8
|
+
"tollFree" => :toll_free, "ttyd" => :ttyd
|
9
|
+
|
10
|
+
end
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module VoteSmart
|
2
|
+
|
3
|
+
class Rating < Common
|
4
|
+
|
5
|
+
# Returns categories with ratings according to state_id(NA = fed)
|
6
|
+
def self.get_categories state_id = nil
|
7
|
+
request("Rating.getCategories", "stateId" => state_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns a list of SIGs with ratings in category and state
|
11
|
+
def self.get_sig_list category_id, state_id = 'NA'
|
12
|
+
request("Rating.getSigList", "category_id" => category_id, "stateId" => state_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns detailed SIG information
|
16
|
+
def self.get_sig sig_id
|
17
|
+
request("Rating.getSig", "sigId" => sig_id)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Returns an SIG's rating on a specific candidate
|
21
|
+
def self.get_candidate_rating candidate_id, sig_id
|
22
|
+
request("Rating.getCandidateRating", "candidateId" => candidate_id, "sigId" => sig_id)
|
23
|
+
end
|
24
|
+
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module VoteSmart
|
2
|
+
|
3
|
+
class State < Common
|
4
|
+
|
5
|
+
attr_accessor :id, :name, :largest_city
|
6
|
+
|
7
|
+
set_attribute_map "stateId" => :id, "name" => :name, "largestCity" => :largest_city
|
8
|
+
|
9
|
+
def self.all
|
10
|
+
response_child(get_state_ids, "stateList", "list", "state").collect {|attributes| State.new(attributes)}
|
11
|
+
end
|
12
|
+
|
13
|
+
def self.find_by_id state_id
|
14
|
+
response = response_child(get_state(state_id), "state", "details")
|
15
|
+
State.new(response) unless response.empty?
|
16
|
+
end
|
17
|
+
|
18
|
+
# Returns a list of states and their 2 digit IDs
|
19
|
+
def self.get_state_ids
|
20
|
+
request("State.getStateIDs")
|
21
|
+
end
|
22
|
+
|
23
|
+
# Returns detailed state information
|
24
|
+
def self.get_state state_id
|
25
|
+
request("State.getState", "stateId" => state_id)
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,70 @@
|
|
1
|
+
module VoteSmart
|
2
|
+
|
3
|
+
class Vote < Common
|
4
|
+
|
5
|
+
# Returns a list of categories with votes assigned for the year and state provided
|
6
|
+
def self.get_categories year, state_id = 'NA'
|
7
|
+
request("Votes.getCategories", "stateId" => state_id)
|
8
|
+
end
|
9
|
+
|
10
|
+
# Returns detailed bill information
|
11
|
+
def self.get_bill bill_id
|
12
|
+
request("Votes.getBill", "billId" => bill_id)
|
13
|
+
end
|
14
|
+
|
15
|
+
# Returns a bill's action/stage(signed by prez, passed senate) detailed information
|
16
|
+
def self.get_bill_action act_id
|
17
|
+
request("Votes.getBillAction", "actionId" => act_id)
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get's a bill's action's votes
|
21
|
+
def self.get_bill_action_votes act_id
|
22
|
+
request("Votes.getBillActionVotes", "actionId" => act_id)
|
23
|
+
end
|
24
|
+
|
25
|
+
# Gets a single candidate's vote on a bill
|
26
|
+
def self.get_bill_action_votes_by_official act_id, can_id
|
27
|
+
request("Votes.getBillActionVoteByOfficial", "actionId" => act_id, "candidateId" => can_id)
|
28
|
+
end
|
29
|
+
|
30
|
+
# Gets a list of bills that fit the criteria
|
31
|
+
def self.get_bills_by_category_year_state category_id, year, state = 'NA'
|
32
|
+
request("Votes.getBillsByCategoryYearState", "categoryId" => category_id, "year" => year, "stateId" => state)
|
33
|
+
end
|
34
|
+
|
35
|
+
# Gets a list of bills that fit the criteria
|
36
|
+
def self.get_bills_by_year_state year, state_id = 'NA'
|
37
|
+
request("Votes.getBillsByYearState", "year" => year, "stateId" => state_id)
|
38
|
+
end
|
39
|
+
|
40
|
+
# Gets a list of bills that fit the criteria
|
41
|
+
def self.get_bills_by_official_year can_id, year
|
42
|
+
request("Votes.getBillsByOfficialYear", "candidateId" => can_id, "year" => year)
|
43
|
+
end
|
44
|
+
|
45
|
+
# Gets a list of bills that fit the criteria
|
46
|
+
def self.get_bills_by_official_category can_id, category_id
|
47
|
+
request("Votes.getBillsByOfficialCategory", "candidateId" => can_id, "categoryId" => category_id)
|
48
|
+
end
|
49
|
+
|
50
|
+
# Gets a list of bills that fit the criteria
|
51
|
+
def self.get_bills_by_sponsor_year can_id, year
|
52
|
+
request("Votes.getBillsBySponsorYear", "candidateId" => can_id, "year" => year)
|
53
|
+
end
|
54
|
+
|
55
|
+
# Gets a list of bills that fit the criteria
|
56
|
+
def self.get_bills_by_sponsor_category can_id, category_id
|
57
|
+
request("Votes.getBillsBySponsorCategory", "candiateId" => can_id, "categoryId" => category_id)
|
58
|
+
end
|
59
|
+
|
60
|
+
# Gets a list of bills that fit the criteria
|
61
|
+
def self.get_bills_by_state_recent ammount, state_id = 'NA'
|
62
|
+
request("Votes.getBillsByStateRecent", "stateId" => state_id, "ammount" => ammount)
|
63
|
+
end
|
64
|
+
|
65
|
+
# Gets a list of vetoes for the provided candidate
|
66
|
+
def self.get_vetoes can_id
|
67
|
+
request("Votes.getVetoes", "candidateId" => can_id)
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|