civic_aide 0.0.3 → 0.1.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.
- checksums.yaml +4 -4
- data/README.md +10 -2
- data/lib/civic_aide/client.rb +4 -2
- data/lib/civic_aide/elections.rb +1 -1
- data/lib/civic_aide/version.rb +1 -1
- data/lib/civic_aide.rb +6 -1
- data/spec/civic_aide/civic_aide_spec.rb +15 -0
- data/spec/civic_aide/client_spec.rb +21 -0
- data/spec/vcr/elections/single.yml +81 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 1ae4a622cfd518c0129d07db8829419441cea136
|
4
|
+
data.tar.gz: c688b4f5eb3ca0a5d7f16ef4cc46ddfa1ccc31e4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e6a27854b2aa259cae4b768c5aac3757001d0e4a20492ea37568b309929c7ab427412f35e9f3f70f287b4a50762e64697774379235b49aad846ad070e914a972
|
7
|
+
data.tar.gz: 8819fd8df652eb375581110ec3b4e177fdfca25c9f287e8ead4cfe111fe3f70822ce8687a15ad1cdb3d45111092d390720a4ed114b8dc5ae17384c1561ac0572
|
data/README.md
CHANGED
@@ -38,8 +38,8 @@ Additionally, to avoid clashing with the [Array#zip Ruby method](http://apidock.
|
|
38
38
|
### Configuration
|
39
39
|
|
40
40
|
```ruby
|
41
|
-
|
42
|
-
client = CivicAide::Client.new(
|
41
|
+
api_key = `ABCaSyD5aMsdmaXxHc7aiUyYuVXtCICV-y_PWnf5w`
|
42
|
+
client = CivicAide::Client.new(api_key)
|
43
43
|
```
|
44
44
|
|
45
45
|
Alternatively, the API key can be set with global configuration and the resources can be accessed directly.
|
@@ -49,6 +49,14 @@ CivicAide.api_key = "ABCaSyD5aMsdmaXxHc7aiUyYuVXtCICV-y_PWnf5w"
|
|
49
49
|
CivicAide.elections.all
|
50
50
|
```
|
51
51
|
|
52
|
+
To [receive data that is only from official state sources](https://developers.google.com/civic-information/docs/us_v1/elections/voterInfoQuery), set `CivicPage.official_sources` to `true`. By default this is set to `false`.
|
53
|
+
|
54
|
+
```ruby
|
55
|
+
CivicAide.official_sources = true
|
56
|
+
# or
|
57
|
+
client.official_sources = true
|
58
|
+
```
|
59
|
+
|
52
60
|
## Resources
|
53
61
|
|
54
62
|
### [Elections](https://developers.google.com/civic-information/docs/us_v1/elections)
|
data/lib/civic_aide/client.rb
CHANGED
@@ -14,10 +14,12 @@ module CivicAide
|
|
14
14
|
headers "User-Agent" => "CivicAide Ruby gem v#{CivicAide::VERSION}".freeze
|
15
15
|
|
16
16
|
attr_reader :api_key
|
17
|
+
attr_accessor :official_only
|
17
18
|
|
18
|
-
def initialize(api_key=nil)
|
19
|
-
@api_key = api_key
|
19
|
+
def initialize(api_key=nil, official_only=nil)
|
20
|
+
@api_key, @official_only = api_key, official_only
|
20
21
|
@api_key ||= CivicAide.api_key
|
22
|
+
@official_only ||= CivicAide.official_only
|
21
23
|
end
|
22
24
|
|
23
25
|
def get(url, query={})
|
data/lib/civic_aide/elections.rb
CHANGED
@@ -14,7 +14,7 @@ module CivicAide
|
|
14
14
|
|
15
15
|
def at(address)
|
16
16
|
raise ElectionIdMissing, "Missing a required election id" if @election_id.nil?
|
17
|
-
response = client.post("/voterinfo/#{election_id}/lookup", {officialOnly:
|
17
|
+
response = client.post("/voterinfo/#{election_id}/lookup", {officialOnly: @client.official_only}, {address: address})
|
18
18
|
response.except!(:kind, :status)
|
19
19
|
end
|
20
20
|
|
data/lib/civic_aide/version.rb
CHANGED
data/lib/civic_aide.rb
CHANGED
@@ -11,6 +11,7 @@ require 'civic_aide/errors'
|
|
11
11
|
module CivicAide
|
12
12
|
class << self
|
13
13
|
extend Forwardable
|
14
|
+
attr_accessor :official_only
|
14
15
|
|
15
16
|
def api_key
|
16
17
|
raise APIKeyNotSet if @api_key.nil?
|
@@ -21,13 +22,17 @@ module CivicAide
|
|
21
22
|
@api_key = api_key
|
22
23
|
end
|
23
24
|
|
25
|
+
def official_only
|
26
|
+
@official_only ||= false
|
27
|
+
end
|
28
|
+
|
24
29
|
delegate [
|
25
30
|
:elections,
|
26
31
|
:representatives
|
27
32
|
] => :client
|
28
33
|
|
29
34
|
def client
|
30
|
-
@client = CivicAide::Client.new(@api_key)
|
35
|
+
@client = CivicAide::Client.new(@api_key, @official_only)
|
31
36
|
end
|
32
37
|
|
33
38
|
end
|
@@ -6,6 +6,10 @@ describe CivicAide do
|
|
6
6
|
CivicAide.api_key = "samplekey"
|
7
7
|
end
|
8
8
|
|
9
|
+
after do
|
10
|
+
CivicAide.official_only = false
|
11
|
+
end
|
12
|
+
|
9
13
|
it 'should include Forwardable' do
|
10
14
|
CivicAide.extend(Forwardable)
|
11
15
|
end
|
@@ -22,4 +26,15 @@ describe CivicAide do
|
|
22
26
|
end
|
23
27
|
end
|
24
28
|
|
29
|
+
describe ".official_only" do
|
30
|
+
it "should default to false" do
|
31
|
+
expect(CivicAide.official_only).to eq(false)
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should allow changing" do
|
35
|
+
CivicAide.official_only = true
|
36
|
+
expect(CivicAide.official_only).to eq(true)
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
25
40
|
end
|
@@ -16,6 +16,10 @@ describe CivicAide::Client do
|
|
16
16
|
CivicAide.api_key = "AIzaSyDWJSisG_4Azd6nVJTU5gdKPiKKTCovupY"
|
17
17
|
expect{ CivicAide::Client.new }.to_not raise_error
|
18
18
|
end
|
19
|
+
|
20
|
+
it "defaults to false for official only" do
|
21
|
+
expect(@client.official_only).to eq(false)
|
22
|
+
end
|
19
23
|
end
|
20
24
|
|
21
25
|
describe "#new" do
|
@@ -102,4 +106,21 @@ describe CivicAide::Client do
|
|
102
106
|
end
|
103
107
|
end
|
104
108
|
|
109
|
+
describe "official only" do
|
110
|
+
it "should allowing toggling official_only" do
|
111
|
+
expect(@client.official_only).to eq(false)
|
112
|
+
end
|
113
|
+
|
114
|
+
it "should allowing toggling official_only" do
|
115
|
+
@client.official_only = true
|
116
|
+
expect(@client.official_only).to eq(true)
|
117
|
+
end
|
118
|
+
|
119
|
+
it "should have client instead of class for official_only" do
|
120
|
+
CivicAide.official_only = true
|
121
|
+
@client.official_only = false
|
122
|
+
expect(@client.official_only).to eq(false)
|
123
|
+
end
|
124
|
+
end
|
125
|
+
|
105
126
|
end
|
@@ -78,6 +78,86 @@ http_interactions:
|
|
78
78
|
P. QUINN","title":"General Registrar Physical","officePhoneNumber":"7033244715","emailAddress":"cameronquinn@fairfaxcounty.gov"}]},"sources":[{"name":"Voting
|
79
79
|
Information Project","official":true}]},"sources":[{"name":"Voting Information
|
80
80
|
Project","official":true}]}]}'
|
81
|
-
http_version:
|
81
|
+
http_version:
|
82
82
|
recorded_at: Fri, 27 Dec 2013 16:20:05 GMT
|
83
|
+
- request:
|
84
|
+
method: post
|
85
|
+
uri: https://www.googleapis.com/civicinfo/us_v1/voterinfo/4015/lookup?key=AIzaSyDWJSisG_4Azd6nVJTU5gdKPiKKTCovupY&officialOnly=true&prettyPrint=false
|
86
|
+
body:
|
87
|
+
encoding: UTF-8
|
88
|
+
string: '{"address":"4910 Willet Drive, Annandale, VA 22003"}'
|
89
|
+
headers:
|
90
|
+
Content-Type:
|
91
|
+
- application/json
|
92
|
+
User-Agent:
|
93
|
+
- CivicAide Ruby gem v0.0.3
|
94
|
+
response:
|
95
|
+
status:
|
96
|
+
code: 200
|
97
|
+
message: OK
|
98
|
+
headers:
|
99
|
+
Cache-Control:
|
100
|
+
- no-cache, no-store, max-age=0, must-revalidate
|
101
|
+
Pragma:
|
102
|
+
- no-cache
|
103
|
+
Expires:
|
104
|
+
- Fri, 01 Jan 1990 00:00:00 GMT
|
105
|
+
Date:
|
106
|
+
- Sun, 29 Dec 2013 19:02:34 GMT
|
107
|
+
Etag:
|
108
|
+
- '"AkiRpOnd7sKoopyUaI9w1UXzdBI/vWeYnvL4AVWs9UxlTsL7NNSRt1U"'
|
109
|
+
Content-Type:
|
110
|
+
- application/json; charset=UTF-8
|
111
|
+
X-Content-Type-Options:
|
112
|
+
- nosniff
|
113
|
+
X-Frame-Options:
|
114
|
+
- SAMEORIGIN
|
115
|
+
X-Xss-Protection:
|
116
|
+
- 1; mode=block
|
117
|
+
Server:
|
118
|
+
- GSE
|
119
|
+
Alternate-Protocol:
|
120
|
+
- 443:quic
|
121
|
+
Transfer-Encoding:
|
122
|
+
- chunked
|
123
|
+
body:
|
124
|
+
encoding: UTF-8
|
125
|
+
string: '{"kind":"civicinfo#voterInfoResponse","status":"success","election":{"id":"4015","name":"VA
|
126
|
+
State Election","electionDay":"2013-11-05"},"normalizedInput":{"line1":"4910
|
127
|
+
willet dr","city":"annandale","state":"VA","zip":"22003"},"contests":[{"type":"general","special":"no","office":"Governor","district":{"name":"Statewide","scope":"statewide"},"ballotPlacement":"4","candidates":[{"name":"Ken
|
128
|
+
T. Cuccinelli II","party":"Republican","candidateUrl":"http://www.cuccinelli.com","phone":"8047863808","email":"ken@cuccinelli.com"},{"name":"Robert
|
129
|
+
C. Sarvis","party":"Libertarian","candidateUrl":"http://www.robertsarvis.com","email":"info@robertsarvis.com"},{"name":"Terry
|
130
|
+
R. McAuliffe","party":"Democrat","candidateUrl":"http://www.terrymcauliffe.com","phone":"7038227604","email":"info@terrymcauliffe.com"}],"sources":[{"name":"Voting
|
131
|
+
Information Project","official":true}]},{"type":"general","special":"no","office":"Lieutenant
|
132
|
+
Governor","district":{"name":"Statewide","scope":"statewide"},"ballotPlacement":"5","candidates":[{"name":"Ralph
|
133
|
+
S. Northam","party":"Democrat","candidateUrl":"http://www.northamforlg.com","phone":"7576954188","email":"ralph@ralphnortham.com"},{"name":"E.
|
134
|
+
W. Jackson","party":"Republican","candidateUrl":"http://www.jacksonforlg.com","phone":"7578024246","email":"jackson@jacksonforlg.com"}],"sources":[{"name":"Voting
|
135
|
+
Information Project","official":true}]},{"type":"general","special":"no","office":"Attorney
|
136
|
+
General","district":{"name":"Statewide","scope":"statewide"},"ballotPlacement":"6","candidates":[{"name":"Mark
|
137
|
+
D. Obenshain","party":"Republican","candidateUrl":"http://www.markobenshain.com","phone":"5404371451","email":"campaign@markobenshain.com"},{"name":"Mark
|
138
|
+
R. Herring","party":"Democrat","candidateUrl":"http://www.herringforag.com","phone":"7036699090","email":"kevin@herringforag.com"}],"sources":[{"name":"Voting
|
139
|
+
Information Project","official":true}]},{"type":"general","special":"no","office":"Member
|
140
|
+
House of Delegates","district":{"name":"039","scope":"stateLower","id":"39"},"ballotPlacement":"8","candidates":[{"name":"Vivian
|
141
|
+
E. Watts","party":"Democrat","candidateUrl":"http://www.vivianwatts.com","phone":"7039782989","email":"vwatts@erols.com"},{"name":"Joe
|
142
|
+
G. Bury","party":"Republican","candidateUrl":"http://www.joebury.com","phone":"7033078221","email":"jgbury@hotmail.com"}],"sources":[{"name":"Voting
|
143
|
+
Information Project","official":true}]},{"type":"general","special":"no","office":"Sheriff","district":{"name":"FAIRFAX
|
144
|
+
COUNTY"},"ballotPlacement":"11","candidates":[{"name":"Stacey Ann Kincaid","party":"Democrat","candidateUrl":"http://staceykincaid.com","phone":"7039381658","email":"Kincaidforsheriff@gmail.com"},{"name":"Christopher
|
145
|
+
F. DeCarlo","party":"Independent","candidateUrl":"http://www.honestyandethics.com","phone":"7035736160","email":"cdecarlo@fairfaxpropane.com"},{"name":"Bryan
|
146
|
+
A. /B. A./ Wolfe","party":"Republican","candidateUrl":"http://www.wolfeforsheriff.com","phone":"7035436360","email":"fairfaxwolfe@yahoo.com"},{"name":"Robert
|
147
|
+
A. Rivera","party":"Independent","phone":"7039783034","email":"riveraforsheriff@gmail.com"}],"sources":[{"name":"Voting
|
148
|
+
Information Project","official":true}]},{"type":"Referendum","special":"no","office":"School
|
149
|
+
Bonds","district":{"name":"FAIRFAX COUNTY","id":"59"},"ballotPlacement":"9999","sources":[{"name":"Voting
|
150
|
+
Information Project","official":true}]}],"state":[{"name":"Virginia","electionAdministrationBody":{"name":"State
|
151
|
+
Board of Elections","electionInfoUrl":"http://www.sbe.virginia.gov/","electionRegistrationUrl":"https://www.vote.virginia.gov/","electionRegistrationConfirmationUrl":"https://www.vote.virginia.gov/","absenteeVotingInfoUrl":"http://www.sbe.virginia.gov/absenteevoting.html","votingLocationFinderUrl":"https://www.vote.virginia.gov/","ballotInfoUrl":"https://www.vote.virginia.gov/","electionRulesUrl":"http://www.sbe.virginia.gov/","physicalAddress":{"locationName":"State
|
152
|
+
Board of Elections","line1":"Washington Building First Floor","line2":"1100
|
153
|
+
Bank Street","city":"Richmond","state":"VA","zip":"23219"}},"local_jurisdiction":{"name":"FAIRFAX
|
154
|
+
COUNTY","electionAdministrationBody":{"name":"FAIRFAX COUNTY","electionInfoUrl":"http://www.fairfaxcounty.gov/elections","electionRegistrationUrl":"http://www.vote.virginia.gov","electionRegistrationConfirmationUrl":"http://www.vote.virginia.gov","absenteeVotingInfoUrl":"http://www.vote.virginia.gov","votingLocationFinderUrl":"http://www.vote.virginia.gov","ballotInfoUrl":"http://www.vote.virginia.gov","electionRulesUrl":"http://www.vote.virginia.gov","hoursOfOperation":"8:00
|
155
|
+
a.m. to 4:30 p.m Monday-Wednesday and Friday and 8:00 a.m. to 7:00 p.m. Thursday","physicalAddress":{"locationName":"FAIRFAX
|
156
|
+
COUNTY","line1":"OFFICE OF ELECTIONS","line2":"12000 GOVERNMENT CENTER PKWY","line3":"SUITE
|
157
|
+
323","city":"FAIRFAX","state":"VA","zip":"22035-0081"},"electionOfficials":[{"name":"CAMERON
|
158
|
+
P. QUINN","title":"General Registrar Physical","officePhoneNumber":"7033244715","emailAddress":"cameronquinn@fairfaxcounty.gov"}]},"sources":[{"name":"Voting
|
159
|
+
Information Project","official":true}]},"sources":[{"name":"Voting Information
|
160
|
+
Project","official":true}]}]}'
|
161
|
+
http_version:
|
162
|
+
recorded_at: Sun, 29 Dec 2013 19:02:35 GMT
|
83
163
|
recorded_with: VCR 2.5.0
|