google-civic 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
File without changes
@@ -0,0 +1,38 @@
1
+ *.gem
2
+ *.rbc
3
+ *.sw[a-p]
4
+ *.tmproj
5
+ *.tmproject
6
+ *.un~
7
+ *~
8
+ .Spotlight-V100
9
+ .Trashes
10
+ ._*
11
+ .bundle
12
+ .config
13
+ .directory
14
+ .elc
15
+ .emacs.desktop
16
+ .emacs.desktop.lock
17
+ .redcar
18
+ .yardoc
19
+ Desktop.ini
20
+ Gemfile.lock
21
+ Icon?
22
+ InstalledFiles
23
+ Session.vim
24
+ \#*\#
25
+ _yardoc
26
+ auto-save-list
27
+ coverage
28
+ doc
29
+ lib/bundler/man
30
+ pkg
31
+ pkg/*
32
+ rdoc
33
+ spec/reports
34
+ test/tmp
35
+ test/version_tmp
36
+ tmp
37
+ tmtags
38
+ tramp
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --order random
@@ -0,0 +1,9 @@
1
+ language: ruby
2
+ matrix:
3
+ allow_failures:
4
+ - rvm: ruby-head
5
+ rvm:
6
+ - rbx-19mode
7
+ - 1.9.2
8
+ - 1.9.3
9
+ - ruby-head
@@ -0,0 +1,3 @@
1
+ --markup markdown
2
+ -
3
+ LICENSE.md
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in gem_template.gemspec
4
+ gemspec
@@ -0,0 +1,21 @@
1
+ Copyright (c) 2012, Ryan Resella
2
+ All rights reserved.
3
+
4
+ Permission is hereby granted, free of charge, to any person obtaining
5
+ a copy of this software and associated documentation files (the
6
+ "Software"), to deal in the Software without restriction, including
7
+ without limitation the rights to use, copy, modify, merge, publish,
8
+ distribute, sublicense, and/or sell copies of the Software, and to
9
+ permit persons to whom the Software is furnished to do so, subject to
10
+ the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be
13
+ included in all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
19
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
20
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
21
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,85 @@
1
+ # Google Civic API [![Build Status](https://secure.travis-ci.org/ryanatwork/google-civic.png)](http://travis-ci.org/ryanatwork/google-civic)
2
+ A Ruby wrapper for the Google Civic API at
3
+ [https://developers.google.com/civic-information/](https://developers.google.com/civic-information/)
4
+
5
+ ## Does your project or organization use this gem?
6
+ Add it to the [apps](http://github.com/ryanatwork/google-civic/wiki/apps) wiki!
7
+
8
+ ## Installation
9
+ gem install google-civic
10
+
11
+ ## Documentation
12
+ [http://rdoc.info/gems/google-civic](http://rdoc.info/gems/google-civic)
13
+
14
+ ## Obtain your API Key
15
+ Make sure to obtain your API key from here [https://developers.google.com/civic-information/docs/using_api](https://developers.google.com/civic-information/docs/using_api)
16
+
17
+
18
+ ## Usage Examples
19
+ require 'google-civic'
20
+
21
+ @client = GoogleCivic.new(:key => "abc123")
22
+
23
+ #elections
24
+ a = @client.elections
25
+ a.elections.first # => #<Hashie::Mash electionDay="2013-06-06" id="2000" name="VIP Test Election">
26
+
27
+ # Voter info
28
+ b = @client.voter_info(2000, '1263 Pacific Ave. Kansas City KS')
29
+ b.pollingLocations.first.address # => #<Hashie::Mash city="Kansas City" line1="100 S 20th St" line2="" line3="" locationName="National Guard Armory" state="KS" zip="66102 ">
30
+
31
+ ## Contributing
32
+ In the spirit of [free software][free-sw], **everyone** is encouraged to help improve
33
+ this project.
34
+
35
+ [free-sw]: http://www.fsf.org/licensing/essays/free-sw.html
36
+
37
+ Here are some ways *you* can contribute:
38
+
39
+ * by using alpha, beta, and prerelease versions
40
+ * by reporting bugs
41
+ * by suggesting new features
42
+ * by writing or editing documentation
43
+ * by writing specifications
44
+ * by writing code (**no patch is too small**: fix typos, add comments, clean up
45
+ inconsistent whitespace)
46
+ * by refactoring code
47
+ * by fixing [issues][]
48
+ * by reviewing patches
49
+
50
+ [issues]: http://github.com/ryanatwork/google-civic/issues
51
+
52
+ ## Submitting an Issue
53
+ We use the [GitHub issue tracker][issues] to track bugs and features. Before
54
+ submitting a bug report or feature request, check to make sure it hasn't
55
+ already been submitted. When submitting a bug report, please include a [Gist][]
56
+ that includes a stack trace and any details that may be necessary to reproduce
57
+ the bug, including your gem version, Ruby version, and operating system.
58
+ Ideally, a bug report should include a pull request with failing specs.
59
+
60
+ [gist]: https://gist.github.com/
61
+
62
+ ## Submitting a Pull Request
63
+ 1. [Fork the repository.][fork]
64
+ 2. [Create a topic branch.][branch]
65
+ 3. Add specs for your unimplemented feature or bug fix.
66
+ 4. Run `bundle exec rake spec`. If your specs pass, return to step 3.
67
+ 5. Implement your feature or bug fix.
68
+ 6. Run `bundle exec rake spec`. If your specs fail, return to step 5.
69
+ 7. Run `open coverage/index.html`. If your changes are not completely covered
70
+ by your tests, return to step 3.
71
+ 8. Add documentation for your feature or bug fix.
72
+ 9. Run `bundle exec rake yard`. If your changes are not 100% documented, go
73
+ back to step 8.
74
+ 10. Add, commit, and push your changes.
75
+ 11. [Submit a pull request.][pr]
76
+
77
+ [fork]: http://help.github.com/fork-a-repo/
78
+ [branch]: http://learn.github.com/p/branching.html
79
+ [pr]: http://help.github.com/send-pull-requests/
80
+
81
+ ## Copyright
82
+ Copyright (c) 2012 Ryan Resella. See [LICENSE][] for details.
83
+
84
+ [license]: https://github.com/ryanatwork/google-civic/blob/master/LICENSE.md
85
+
@@ -0,0 +1,16 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
3
+
4
+ require 'rspec/core/rake_task'
5
+ RSpec::Core::RakeTask.new(:spec)
6
+
7
+ task :default => :spec
8
+ task :test => :spec
9
+
10
+ require 'yard'
11
+ namespace :doc do
12
+ YARD::Rake::YardocTask.new do |task|
13
+ task.files = ['LICENSE.md', 'lib/**/*.rb']
14
+ task.options = ['--markup', 'markdown']
15
+ end
16
+ end
@@ -0,0 +1,27 @@
1
+ # encoding: utf-8
2
+ require File.expand_path('../lib/google-civic/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.add_dependency 'addressable', '~> 2.2'
6
+ gem.add_dependency 'faraday', '~> 0.8'
7
+ gem.add_dependency 'faraday_middleware', '~> 0.8'
8
+ gem.add_dependency 'hashie', '~> 1.2'
9
+ gem.add_dependency 'multi_json', '~> 1.3'
10
+ gem.add_development_dependency 'rake'
11
+ gem.add_development_dependency 'rdiscount'
12
+ gem.add_development_dependency 'rspec'
13
+ gem.add_development_dependency 'simplecov'
14
+ gem.add_development_dependency 'webmock'
15
+ gem.add_development_dependency 'yard'
16
+ gem.author = "Ryan Resella"
17
+ gem.description = %q{A Ruby wrapper for the Google Civic API}
18
+ gem.email = 'ryan@codeforamerica.org'
19
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{|f| File.basename(f)}
20
+ gem.files = `git ls-files`.split("\n")
21
+ gem.homepage = ''
22
+ gem.name = 'google-civic'
23
+ gem.require_paths = ['lib']
24
+ gem.summary = gem.description
25
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
+ gem.version = GoogleCivic::VERSION
27
+ end
@@ -0,0 +1,22 @@
1
+ require 'google-civic/client'
2
+
3
+ module GoogleCivic
4
+ class << self
5
+ # Alias for GoogleCivic::Client.new
6
+ #
7
+ # @return [GoogleCivic::Client]
8
+ def new(options={})
9
+ GoogleCivic::Client.new(options)
10
+ end
11
+
12
+ # Delegate to GoogleCivic::Client.new
13
+ def method_missing(method, *args, &block)
14
+ return super unless new.respond_to?(method)
15
+ new.send(method, *args, &block)
16
+ end
17
+
18
+ def respond_to?(method, include_private=false)
19
+ new.respond_to?(method, include_private) || super(method, include_private)
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,37 @@
1
+ require 'google-civic/connection'
2
+ require 'google-civic/request'
3
+
4
+ module GoogleCivic
5
+ class Client
6
+ def initialize(options={})
7
+ @key = options[:key]
8
+ end
9
+
10
+ include GoogleCivic::Connection
11
+ include GoogleCivic::Request
12
+
13
+ # Gets a list of elections in the API
14
+ #
15
+ # @return [Hashie::Mash] A list of current elections in the API
16
+ # @see https://developers.google.com/civic-information/docs/us_v1/elections/electionQuery
17
+ # @example List the current elections
18
+ # GoogleCivic.elections
19
+ def elections(options={})
20
+ get("elections", options)
21
+ end
22
+
23
+ # Looks up information relevant to a voter based on the voter's registered address.
24
+ #
25
+ # @param election_id [Integer] The id of the election found in .elections
26
+ # @param address [String] The address to search on.
27
+ # @param options [Hash] A customizable set of options.
28
+ # @return [Hashie::Mash] A list of current information around the voter
29
+ # @see https://developers.google.com/civic-information/docs/us_v1/elections/voterInfoQuery
30
+ # @example List information around the voter
31
+ # GoogleCivic.voter_info(200, '1263 Pacific Ave. Kansas City KS')
32
+ def voter_info(election_id, address, options={})
33
+ post("voterinfo/#{election_id}/lookup", options.merge({:address => address}))
34
+ end
35
+
36
+ end
37
+ end
@@ -0,0 +1,22 @@
1
+ require 'faraday_middleware'
2
+
3
+ module GoogleCivic
4
+ # @private
5
+ module Connection
6
+ private
7
+
8
+ def connection(json, options={})
9
+ connection = Faraday.new(options.merge({:url => 'https://www.googleapis.com/civicinfo/us_v1/'})) do |builder|
10
+ if json
11
+ builder.request :json
12
+ else
13
+ builder.request :url_encoded
14
+ end
15
+ builder.use FaradayMiddleware::Mashify
16
+ builder.use FaradayMiddleware::ParseJson
17
+ builder.adapter Faraday.default_adapter
18
+ end
19
+ connection
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,25 @@
1
+ require 'multi_json'
2
+
3
+ module GoogleCivic
4
+ module Request
5
+ def get(path, options={})
6
+ request(:get, path, json=false,options)
7
+ end
8
+
9
+ def post(path, options={})
10
+ request(:post, path, json=true,options)
11
+ end
12
+
13
+ private
14
+
15
+ def request(method, path, json,options)
16
+ response = connection(json).send(method) do |request|
17
+ request.url(path, options.merge(:key => @key))
18
+ if json
19
+ request.body = options.to_json
20
+ end
21
+ end
22
+ response.body
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,3 @@
1
+ module GoogleCivic
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,15 @@
1
+ {
2
+ "kind": "civicinfo#electionsqueryresponse",
3
+ "elections": [
4
+ {
5
+ "id": "2000",
6
+ "name": "VIP Test Election",
7
+ "electionDay": "2013-06-06"
8
+ },
9
+ {
10
+ "id": "4000",
11
+ "name": "U.S. 2012 General Election",
12
+ "electionDay": "2012-11-06"
13
+ }
14
+ ]
15
+ }
@@ -0,0 +1,484 @@
1
+ {
2
+ "kind": "civicinfo#voterinforesponse",
3
+ "status": "success",
4
+ "election": {
5
+ "id": "2000",
6
+ "name": "VIP Test Election",
7
+ "electionDay": "2013-06-06"
8
+ },
9
+ "normalizedInput": {
10
+ "line1": "1263 Pacific Ave",
11
+ "city": "Kansas City",
12
+ "state": "KS",
13
+ "zip": "66102"
14
+ },
15
+ "pollingLocations": [
16
+ {
17
+ "address": {
18
+ "locationName": "National Guard Armory",
19
+ "line1": "100 S 20th St",
20
+ "line2": "",
21
+ "line3": "",
22
+ "city": "Kansas City",
23
+ "state": "KS",
24
+ "zip": "66102 "
25
+ },
26
+ "pollingHours": " - ",
27
+ "sources": [
28
+ {
29
+ "name": "Voting Information Project",
30
+ "official": true
31
+ }
32
+ ]
33
+ }
34
+ ],
35
+ "contests": [
36
+ {
37
+ "type": "General",
38
+ "office": "Attorney",
39
+ "district": {
40
+ "name": "Attorney",
41
+ "scope": "countywide",
42
+ "id": "4"
43
+ },
44
+ "sources": [
45
+ {
46
+ "name": "Voting Information Project",
47
+ "official": true
48
+ }
49
+ ]
50
+ },
51
+ {
52
+ "type": "General",
53
+ "office": "Sheriff",
54
+ "district": {
55
+ "name": "Sheriff",
56
+ "scope": "countywide",
57
+ "id": "5"
58
+ },
59
+ "sources": [
60
+ {
61
+ "name": "Voting Information Project",
62
+ "official": true
63
+ }
64
+ ]
65
+ },
66
+ {
67
+ "type": "General",
68
+ "office": "Kansas Representative 32",
69
+ "district": {
70
+ "name": "Kansas Representative 32",
71
+ "scope": "stateLower",
72
+ "id": "32"
73
+ },
74
+ "sources": [
75
+ {
76
+ "name": "Voting Information Project",
77
+ "official": true
78
+ }
79
+ ]
80
+ },
81
+ {
82
+ "type": "General",
83
+ "office": "Governor/Lt. Governor",
84
+ "district": {
85
+ "name": "Governor/Lt. Governor",
86
+ "scope": "statewide",
87
+ "id": "1"
88
+ },
89
+ "candidates": [
90
+ {
91
+ "name": "Andrew P. Gray",
92
+ "party": "Libertarian",
93
+ "email": "chair@lpks.org"
94
+ },
95
+ {
96
+ "name": "Kenneth (ken) W. Cannon",
97
+ "party": "Reform"
98
+ },
99
+ {
100
+ "name": "Tom Holland",
101
+ "party": "Democratic",
102
+ "candidateUrl": "www.tomhollandforkansas.com",
103
+ "email": "info@tomhollandforkansas.com"
104
+ },
105
+ {
106
+ "name": "Sam Brownback",
107
+ "party": "Republican",
108
+ "candidateUrl": "www.brownbackforkansas.com",
109
+ "email": "media@brownback.com"
110
+ }
111
+ ],
112
+ "sources": [
113
+ {
114
+ "name": "Voting Information Project",
115
+ "official": true
116
+ }
117
+ ]
118
+ },
119
+ {
120
+ "type": "General",
121
+ "office": "KCKCC Member AL Brd of Trustee",
122
+ "district": {
123
+ "name": "KCKCC Member AL Brd of Trustee"
124
+ },
125
+ "sources": [
126
+ {
127
+ "name": "Voting Information Project",
128
+ "official": true
129
+ }
130
+ ]
131
+ },
132
+ {
133
+ "type": "General",
134
+ "office": "Secretary of State",
135
+ "district": {
136
+ "name": "Secretary of State",
137
+ "scope": "statewide",
138
+ "id": "2"
139
+ },
140
+ "candidates": [
141
+ {
142
+ "name": "Chris Biggs",
143
+ "party": "Democratic"
144
+ },
145
+ {
146
+ "name": "Kris Kobach",
147
+ "party": "Republican"
148
+ },
149
+ {
150
+ "name": "Phillip Horatio Lucas",
151
+ "party": "Libertarian"
152
+ },
153
+ {
154
+ "name": "Derek Langseth",
155
+ "party": "Reform"
156
+ }
157
+ ],
158
+ "sources": [
159
+ {
160
+ "name": "Voting Information Project",
161
+ "official": true
162
+ }
163
+ ]
164
+ },
165
+ {
166
+ "type": "General",
167
+ "office": "U.S. Senate",
168
+ "district": {
169
+ "name": "U.S. Senate",
170
+ "scope": "statewide",
171
+ "id": "5"
172
+ },
173
+ "candidates": [
174
+ {
175
+ "name": "Lisa Johnston",
176
+ "party": "Democratic",
177
+ "candidateUrl": "www.lisaforkansas.com",
178
+ "phone": "913-662-1457",
179
+ "email": "lisa@lisaforkansas.com"
180
+ },
181
+ {
182
+ "name": "Jerry Moran",
183
+ "party": "Republican"
184
+ },
185
+ {
186
+ "name": "Michael Wm. Dann",
187
+ "party": "Libertarian"
188
+ },
189
+ {
190
+ "name": "Joseph (joe) K. Bellis",
191
+ "party": "Reform"
192
+ }
193
+ ],
194
+ "sources": [
195
+ {
196
+ "name": "Voting Information Project",
197
+ "official": true
198
+ }
199
+ ]
200
+ },
201
+ {
202
+ "type": "General",
203
+ "office": "BD of Public Utilities 2",
204
+ "district": {
205
+ "name": "BD of Public Utilities 2",
206
+ "id": "2"
207
+ },
208
+ "sources": [
209
+ {
210
+ "name": "Voting Information Project",
211
+ "official": true
212
+ }
213
+ ]
214
+ },
215
+ {
216
+ "type": "General",
217
+ "office": "Attorney General",
218
+ "district": {
219
+ "name": "Attorney General",
220
+ "scope": "statewide",
221
+ "id": "3"
222
+ },
223
+ "candidates": [
224
+ {
225
+ "name": "Steve Six",
226
+ "party": "Democratic"
227
+ },
228
+ {
229
+ "name": "Derek Schmidt",
230
+ "party": "Republican"
231
+ },
232
+ {
233
+ "name": "Dennis Hawver",
234
+ "party": "Libertarian"
235
+ }
236
+ ],
237
+ "sources": [
238
+ {
239
+ "name": "Voting Information Project",
240
+ "official": true
241
+ }
242
+ ]
243
+ },
244
+ {
245
+ "type": "General",
246
+ "office": "Governor/Lt. Governor",
247
+ "district": {
248
+ "name": "Governor/Lt. Governor",
249
+ "scope": "statewide",
250
+ "id": "1"
251
+ },
252
+ "candidates": [
253
+ {
254
+ "name": "Andrew P. Gray",
255
+ "party": "Libertarian",
256
+ "email": "chair@lpks.org"
257
+ },
258
+ {
259
+ "name": "Kenneth (ken) W. Cannon",
260
+ "party": "Reform"
261
+ },
262
+ {
263
+ "name": "Tom Holland",
264
+ "party": "Democratic",
265
+ "candidateUrl": "www.tomhollandforkansas.com",
266
+ "email": "info@tomhollandforkansas.com"
267
+ },
268
+ {
269
+ "name": "Sam Brownback",
270
+ "party": "Republican",
271
+ "candidateUrl": "www.brownbackforkansas.com",
272
+ "email": "media@brownback.com"
273
+ }
274
+ ],
275
+ "sources": [
276
+ {
277
+ "name": "Voting Information Project",
278
+ "official": true
279
+ }
280
+ ]
281
+ },
282
+ {
283
+ "type": "General",
284
+ "office": "U.S. Representative 3",
285
+ "district": {
286
+ "name": "U.S. Representative 3",
287
+ "scope": "congressional",
288
+ "id": "3"
289
+ },
290
+ "sources": [
291
+ {
292
+ "name": "Voting Information Project",
293
+ "official": true
294
+ }
295
+ ]
296
+ },
297
+ {
298
+ "type": "General",
299
+ "office": "Commissioner-At-Large 2",
300
+ "district": {
301
+ "name": "Commissioner-At-Large 2",
302
+ "id": "2"
303
+ },
304
+ "sources": [
305
+ {
306
+ "name": "Voting Information Project",
307
+ "official": true
308
+ }
309
+ ]
310
+ },
311
+ {
312
+ "type": "General",
313
+ "office": "Kansas Senate 6",
314
+ "district": {
315
+ "name": "Kansas Senate 6",
316
+ "scope": "stateUpper",
317
+ "id": "6"
318
+ },
319
+ "sources": [
320
+ {
321
+ "name": "Voting Information Project",
322
+ "official": true
323
+ }
324
+ ]
325
+ },
326
+ {
327
+ "type": "General",
328
+ "office": "Clerk",
329
+ "district": {
330
+ "name": "Clerk",
331
+ "scope": "countywide",
332
+ "id": "1"
333
+ },
334
+ "sources": [
335
+ {
336
+ "name": "Voting Information Project",
337
+ "official": true
338
+ }
339
+ ]
340
+ },
341
+ {
342
+ "type": "General",
343
+ "office": "President / Vice President",
344
+ "district": {
345
+ "name": "President / Vice President",
346
+ "id": "6"
347
+ },
348
+ "sources": [
349
+ {
350
+ "name": "Voting Information Project",
351
+ "official": true
352
+ }
353
+ ]
354
+ },
355
+ {
356
+ "type": "General",
357
+ "office": "Register of Deeds",
358
+ "district": {
359
+ "name": "Register of Deeds",
360
+ "scope": "countywide",
361
+ "id": "3"
362
+ },
363
+ "sources": [
364
+ {
365
+ "name": "Voting Information Project",
366
+ "official": true
367
+ }
368
+ ]
369
+ },
370
+ {
371
+ "type": "General",
372
+ "office": "USD 500",
373
+ "district": {
374
+ "name": "USD 500",
375
+ "id": "500"
376
+ },
377
+ "sources": [
378
+ {
379
+ "name": "Voting Information Project",
380
+ "official": true
381
+ }
382
+ ]
383
+ },
384
+ {
385
+ "type": "General",
386
+ "office": "Treasurer",
387
+ "district": {
388
+ "name": "Treasurer",
389
+ "scope": "countywide",
390
+ "id": "2"
391
+ },
392
+ "sources": [
393
+ {
394
+ "name": "Voting Information Project",
395
+ "official": true
396
+ }
397
+ ]
398
+ },
399
+ {
400
+ "type": "General",
401
+ "office": "Commissioner 2",
402
+ "district": {
403
+ "name": "Commissioner 2",
404
+ "id": "2"
405
+ },
406
+ "sources": [
407
+ {
408
+ "name": "Voting Information Project",
409
+ "official": true
410
+ }
411
+ ]
412
+ },
413
+ {
414
+ "type": "General",
415
+ "office": "BD of Public Utilities (AL)",
416
+ "district": {
417
+ "name": "BD of Public Utilities (AL)"
418
+ },
419
+ "sources": [
420
+ {
421
+ "name": "Voting Information Project",
422
+ "official": true
423
+ }
424
+ ]
425
+ },
426
+ {
427
+ "type": "General",
428
+ "office": "State Board of Education 1",
429
+ "district": {
430
+ "name": "State Board of Education 1",
431
+ "id": "1"
432
+ },
433
+ "sources": [
434
+ {
435
+ "name": "Voting Information Project",
436
+ "official": true
437
+ }
438
+ ]
439
+ }
440
+ ],
441
+ "state": [
442
+ {
443
+ "name": "State of Kansas",
444
+ "electionAdministrationBody": {
445
+ "name": "Kansas",
446
+ "electionOfficials": [
447
+ {
448
+ "name": "Brad Bryant",
449
+ "title": "Election Director",
450
+ "officePhoneNumber": "785-296-4561",
451
+ "emailAddress": "cclark@essvote.com"
452
+ }
453
+ ]
454
+ },
455
+ "local_jurisdiction": {
456
+ "name": "Wyandotte",
457
+ "electionAdministrationBody": {
458
+ "name": "Wyandotte",
459
+ "electionInfoUrl": "http://www.wycokck.org/election",
460
+ "electionOfficials": [
461
+ {
462
+ "name": "Bruce Newby",
463
+ "title": "Election Commissioner",
464
+ "officePhoneNumber": "(913) 573-8500",
465
+ "emailAddress": "hbbrooks@essvote.com"
466
+ }
467
+ ]
468
+ },
469
+ "sources": [
470
+ {
471
+ "name": "Voting Information Project",
472
+ "official": true
473
+ }
474
+ ]
475
+ },
476
+ "sources": [
477
+ {
478
+ "name": "Voting Information Project",
479
+ "official": true
480
+ }
481
+ ]
482
+ }
483
+ ]
484
+ }
@@ -0,0 +1,37 @@
1
+ require 'helper'
2
+
3
+ describe GoogleCivic::Client do
4
+ it 'should work with an api key' do
5
+ stub_get("https://www.googleapis.com/civicinfo/us_v1/elections?key=abc123").
6
+ with(:headers => {'Accept'=>'*/*'}).
7
+ to_return(:status => 200, :body => '', :headers => {})
8
+ proc {
9
+ GoogleCivic::Client.new(:key=> "abc123")
10
+ }.should_not raise_exception
11
+ end
12
+
13
+ before do
14
+ @client = GoogleCivic::Client.new(:key => "abc123")
15
+ end
16
+
17
+ describe "#elections" do
18
+ it "should list the elections in the API" do
19
+ stub_get("/elections?key=abc123").
20
+ to_return(:status => 200, :body => fixture("elections.json"), :headers => {})
21
+ elections = @client.elections
22
+ elections.first.should == ["kind", "civicinfo#electionsqueryresponse"]
23
+ end
24
+ end
25
+
26
+ describe "#voter_info" do
27
+ it "should return the voter information from an address" do
28
+ stub_post("/voterinfo/2000/lookup?address=1263%20Pacific%20Ave.%20Kansas%20City%20KS&key=abc123").
29
+ with(:body => "{\"address\":\"1263 Pacific Ave. Kansas City KS\"}",
30
+ :headers => {'Accept'=>'*/*', 'Content-Type'=>'application/json', 'User-Agent'=>'Ruby'}).
31
+ to_return(:status => 200, :body => fixture("voter_info.json"), :headers => {})
32
+ voter_info = @client.voter_info(2000, "1263 Pacific Ave. Kansas City KS")
33
+ voter_info.election.name.should == "VIP Test Election"
34
+ end
35
+ end
36
+
37
+ end
@@ -0,0 +1,25 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require 'helper'
3
+
4
+ describe GoogleCivic do
5
+ describe ".respond_to?" do
6
+ it "should be true if method exists" do
7
+ GoogleCivic.respond_to?(:new, true).should be_true
8
+ end
9
+ end
10
+
11
+ describe ".new" do
12
+ it "should be a GoogleCivic::Client" do
13
+ GoogleCivic.new.should be_a GoogleCivic::Client
14
+ end
15
+ end
16
+
17
+ describe ".delegate" do
18
+ it "should delegate missing methods to GoogleCivic::Client" do
19
+ stub_get("/elections?key").
20
+ to_return(:status => 200, :body => fixture("elections.json"), :headers => {})
21
+ elections = GoogleCivic.elections
22
+ elections.first.should == ["kind", "civicinfo#electionsqueryresponse"]
23
+ end
24
+ end
25
+ end
@@ -0,0 +1,61 @@
1
+ unless ENV['CI']
2
+ require 'simplecov'
3
+ SimpleCov.start do
4
+ add_filter 'spec'
5
+ end
6
+ end
7
+ require 'google-civic'
8
+ require 'rspec'
9
+ require 'webmock/rspec'
10
+
11
+ def a_delete(url)
12
+ a_request(:delete, google_url(url))
13
+ end
14
+
15
+ def a_get(url)
16
+ a_request(:get, google_url(url))
17
+ end
18
+
19
+ def a_patch(url)
20
+ a_request(:patch, google_url(url))
21
+ end
22
+
23
+ def a_post(url)
24
+ a_request(:post, google_url(url))
25
+ end
26
+
27
+ def a_put(url)
28
+ a_request(:put, google_url(url))
29
+ end
30
+
31
+ def stub_delete(url)
32
+ stub_request(:delete, google_url(url))
33
+ end
34
+
35
+ def stub_get(url)
36
+ stub_request(:get, google_url(url))
37
+ end
38
+
39
+ def stub_patch(url)
40
+ stub_request(:patch, google_url(url))
41
+ end
42
+
43
+ def stub_post(url)
44
+ stub_request(:post, google_url(url))
45
+ end
46
+
47
+ def stub_put(url)
48
+ stub_request(:put, google_url(url))
49
+ end
50
+
51
+ def fixture_path
52
+ File.expand_path("../fixtures", __FILE__)
53
+ end
54
+
55
+ def fixture(file)
56
+ File.new(fixture_path + '/' + file)
57
+ end
58
+
59
+ def google_url(url)
60
+ "https://www.googleapis.com/civicinfo/us_v1#{url}"
61
+ end
metadata ADDED
@@ -0,0 +1,246 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google-civic
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Ryan Resella
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-09-28 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: addressable
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ~>
20
+ - !ruby/object:Gem::Version
21
+ version: '2.2'
22
+ type: :runtime
23
+ prerelease: false
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '2.2'
30
+ - !ruby/object:Gem::Dependency
31
+ name: faraday
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ~>
36
+ - !ruby/object:Gem::Version
37
+ version: '0.8'
38
+ type: :runtime
39
+ prerelease: false
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ~>
44
+ - !ruby/object:Gem::Version
45
+ version: '0.8'
46
+ - !ruby/object:Gem::Dependency
47
+ name: faraday_middleware
48
+ requirement: !ruby/object:Gem::Requirement
49
+ none: false
50
+ requirements:
51
+ - - ~>
52
+ - !ruby/object:Gem::Version
53
+ version: '0.8'
54
+ type: :runtime
55
+ prerelease: false
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ~>
60
+ - !ruby/object:Gem::Version
61
+ version: '0.8'
62
+ - !ruby/object:Gem::Dependency
63
+ name: hashie
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ~>
68
+ - !ruby/object:Gem::Version
69
+ version: '1.2'
70
+ type: :runtime
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ~>
76
+ - !ruby/object:Gem::Version
77
+ version: '1.2'
78
+ - !ruby/object:Gem::Dependency
79
+ name: multi_json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ~>
84
+ - !ruby/object:Gem::Version
85
+ version: '1.3'
86
+ type: :runtime
87
+ prerelease: false
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ~>
92
+ - !ruby/object:Gem::Version
93
+ version: '1.3'
94
+ - !ruby/object:Gem::Dependency
95
+ name: rake
96
+ requirement: !ruby/object:Gem::Requirement
97
+ none: false
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: '0'
102
+ type: :development
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
110
+ - !ruby/object:Gem::Dependency
111
+ name: rdiscount
112
+ requirement: !ruby/object:Gem::Requirement
113
+ none: false
114
+ requirements:
115
+ - - ! '>='
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ none: false
122
+ requirements:
123
+ - - ! '>='
124
+ - !ruby/object:Gem::Version
125
+ version: '0'
126
+ - !ruby/object:Gem::Dependency
127
+ name: rspec
128
+ requirement: !ruby/object:Gem::Requirement
129
+ none: false
130
+ requirements:
131
+ - - ! '>='
132
+ - !ruby/object:Gem::Version
133
+ version: '0'
134
+ type: :development
135
+ prerelease: false
136
+ version_requirements: !ruby/object:Gem::Requirement
137
+ none: false
138
+ requirements:
139
+ - - ! '>='
140
+ - !ruby/object:Gem::Version
141
+ version: '0'
142
+ - !ruby/object:Gem::Dependency
143
+ name: simplecov
144
+ requirement: !ruby/object:Gem::Requirement
145
+ none: false
146
+ requirements:
147
+ - - ! '>='
148
+ - !ruby/object:Gem::Version
149
+ version: '0'
150
+ type: :development
151
+ prerelease: false
152
+ version_requirements: !ruby/object:Gem::Requirement
153
+ none: false
154
+ requirements:
155
+ - - ! '>='
156
+ - !ruby/object:Gem::Version
157
+ version: '0'
158
+ - !ruby/object:Gem::Dependency
159
+ name: webmock
160
+ requirement: !ruby/object:Gem::Requirement
161
+ none: false
162
+ requirements:
163
+ - - ! '>='
164
+ - !ruby/object:Gem::Version
165
+ version: '0'
166
+ type: :development
167
+ prerelease: false
168
+ version_requirements: !ruby/object:Gem::Requirement
169
+ none: false
170
+ requirements:
171
+ - - ! '>='
172
+ - !ruby/object:Gem::Version
173
+ version: '0'
174
+ - !ruby/object:Gem::Dependency
175
+ name: yard
176
+ requirement: !ruby/object:Gem::Requirement
177
+ none: false
178
+ requirements:
179
+ - - ! '>='
180
+ - !ruby/object:Gem::Version
181
+ version: '0'
182
+ type: :development
183
+ prerelease: false
184
+ version_requirements: !ruby/object:Gem::Requirement
185
+ none: false
186
+ requirements:
187
+ - - ! '>='
188
+ - !ruby/object:Gem::Version
189
+ version: '0'
190
+ description: A Ruby wrapper for the Google Civic API
191
+ email: ryan@codeforamerica.org
192
+ executables: []
193
+ extensions: []
194
+ extra_rdoc_files: []
195
+ files:
196
+ - .gemtest
197
+ - .gitignore
198
+ - .rspec
199
+ - .travis.yml
200
+ - .yardopts
201
+ - Gemfile
202
+ - LICENSE.md
203
+ - README.md
204
+ - Rakefile
205
+ - google-civic.gemspec
206
+ - lib/google-civic.rb
207
+ - lib/google-civic/client.rb
208
+ - lib/google-civic/connection.rb
209
+ - lib/google-civic/request.rb
210
+ - lib/google-civic/version.rb
211
+ - spec/fixtures/elections.json
212
+ - spec/fixtures/voter_info.json
213
+ - spec/google-civic/client_spec.rb
214
+ - spec/google-civic_spec.rb
215
+ - spec/helper.rb
216
+ homepage: ''
217
+ licenses: []
218
+ post_install_message:
219
+ rdoc_options: []
220
+ require_paths:
221
+ - lib
222
+ required_ruby_version: !ruby/object:Gem::Requirement
223
+ none: false
224
+ requirements:
225
+ - - ! '>='
226
+ - !ruby/object:Gem::Version
227
+ version: '0'
228
+ required_rubygems_version: !ruby/object:Gem::Requirement
229
+ none: false
230
+ requirements:
231
+ - - ! '>='
232
+ - !ruby/object:Gem::Version
233
+ version: '0'
234
+ requirements: []
235
+ rubyforge_project:
236
+ rubygems_version: 1.8.24
237
+ signing_key:
238
+ specification_version: 3
239
+ summary: A Ruby wrapper for the Google Civic API
240
+ test_files:
241
+ - spec/fixtures/elections.json
242
+ - spec/fixtures/voter_info.json
243
+ - spec/google-civic/client_spec.rb
244
+ - spec/google-civic_spec.rb
245
+ - spec/helper.rb
246
+ has_rdoc: