civic_info 1.0.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/.gitignore ADDED
@@ -0,0 +1 @@
1
+ *.gem
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'http://rubygems.org'
2
+ gemspec
3
+
4
+ gem 'active_support'
5
+ gem 'httparty'
6
+ gem 'rspec'
data/Gemfile.lock ADDED
@@ -0,0 +1,36 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ civic_info (0.0.0)
5
+ active_support
6
+ httparty
7
+
8
+ GEM
9
+ remote: http://rubygems.org/
10
+ specs:
11
+ active_support (3.0.0)
12
+ activesupport (= 3.0.0)
13
+ activesupport (3.0.0)
14
+ diff-lcs (1.1.3)
15
+ httparty (0.9.0)
16
+ multi_json (~> 1.0)
17
+ multi_xml
18
+ multi_json (1.3.7)
19
+ multi_xml (0.5.1)
20
+ rspec (2.11.0)
21
+ rspec-core (~> 2.11.0)
22
+ rspec-expectations (~> 2.11.0)
23
+ rspec-mocks (~> 2.11.0)
24
+ rspec-core (2.11.1)
25
+ rspec-expectations (2.11.3)
26
+ diff-lcs (~> 1.1.3)
27
+ rspec-mocks (2.11.3)
28
+
29
+ PLATFORMS
30
+ ruby
31
+
32
+ DEPENDENCIES
33
+ active_support
34
+ civic_info!
35
+ httparty
36
+ rspec
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = 'civic_info'
3
+ s.version = '1.0.0'
4
+ s.date = '2012-11-03'
5
+ s.summary = 'Wrapper to Google\'s civic info API'
6
+ s.description = ""
7
+ s.authors = ['J. Cheng']
8
+ s.email = 'chengjoanne2@gmail.com'
9
+ s.files = [`git ls-files`.split($\)]
10
+ s.test_files = s.files.grep(%r{^(test|spec|features)/})
11
+ s.homepage = 'http://github.com/joannecheng/civic_info'
12
+
13
+ s.add_dependency "httparty"
14
+ s.add_dependency 'active_support'
15
+ end
data/lib/civic_info.rb ADDED
@@ -0,0 +1,43 @@
1
+ require 'httparty'
2
+ require 'active_support/core_ext/hash/indifferent_access'
3
+
4
+ class GoogleAPI
5
+
6
+ def initialize(api_key, service_name)
7
+ @api_key = ENV['GOOGLE_API_KEY']
8
+ @service_url = "https://www.googleapis.com#{service_name}"
9
+ end
10
+
11
+ def get(call_string)
12
+ HTTParty.get("#{@service_url}#{call_string}?key=#{@api_key}").with_indifferent_access
13
+ end
14
+
15
+ def post(call_string, body = {})
16
+ HTTParty.post("#{@service_url}#{call_string}?key=#{@api_key}",
17
+ :body => body
18
+ ).with_indifferent_access
19
+ end
20
+
21
+
22
+ end
23
+
24
+ class CivicInfo
25
+
26
+ def initialize
27
+ raise if ENV['GOOGLE_API_KEY'].nil?
28
+ @google_api = GoogleAPI.new(ENV['GOOGLE_API_KEY'], '/civicinfo/us_v1/')
29
+ end
30
+
31
+ def elections
32
+ call_string = 'elections'
33
+ @google_api.get(call_string)
34
+ end
35
+
36
+ def voter_info(election_id, address)
37
+ call_string = "voterinfo/#{election_id}/lookup"
38
+ body = { :address => address }
39
+
40
+ @google_api.post(call_string, body)
41
+ end
42
+
43
+ end
@@ -0,0 +1,7 @@
1
+ require 'rspec'
2
+ require 'bundler/setup'
3
+ require 'civic_info'
4
+
5
+ RSpec.configure do |config|
6
+
7
+ end
@@ -0,0 +1,34 @@
1
+ require 'spec_helper'
2
+
3
+ describe CivicInfo do
4
+ describe '#initialize' do
5
+ context 'has api key' do
6
+ it 'have a google api key' do
7
+ ci = CivicInfo.new()
8
+ ci.instance_variable_get(:@google_api).class.should == GoogleAPI
9
+ end
10
+ end
11
+
12
+ context 'no api key' do
13
+ it 'fails' do
14
+ pending 'how to fake env variables?'
15
+ -> {CivicInfo.new() }.should raise_error
16
+ end
17
+ end
18
+ end
19
+
20
+ describe '#elections' do
21
+ it 'gets election info' do
22
+ ci = CivicInfo.new()
23
+ ci.elections[:kind].should == 'civicinfo#electionsQueryResponse'
24
+ end
25
+ end
26
+
27
+ describe '#voter_info' do
28
+ it 'gets voter info' do
29
+ ci = CivicInfo.new()
30
+ ci.voter_info(4000, 'Market Street Station Denver, CO')
31
+ end
32
+ end
33
+
34
+ end
metadata ADDED
@@ -0,0 +1,85 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: civic_info
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - J. Cheng
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-11-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: httparty
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
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: '0'
30
+ - !ruby/object:Gem::Dependency
31
+ name: active_support
32
+ requirement: !ruby/object:Gem::Requirement
33
+ none: false
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
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'
46
+ description: ''
47
+ email: chengjoanne2@gmail.com
48
+ executables: []
49
+ extensions: []
50
+ extra_rdoc_files: []
51
+ files:
52
+ - .gitignore
53
+ - Gemfile
54
+ - Gemfile.lock
55
+ - civic_info.gemspec
56
+ - lib/civic_info.rb
57
+ - spec/spec_helper.rb
58
+ - spec/unit/civic_info_spec.rb
59
+ homepage: http://github.com/joannecheng/civic_info
60
+ licenses: []
61
+ post_install_message:
62
+ rdoc_options: []
63
+ require_paths:
64
+ - lib
65
+ required_ruby_version: !ruby/object:Gem::Requirement
66
+ none: false
67
+ requirements:
68
+ - - ! '>='
69
+ - !ruby/object:Gem::Version
70
+ version: '0'
71
+ required_rubygems_version: !ruby/object:Gem::Requirement
72
+ none: false
73
+ requirements:
74
+ - - ! '>='
75
+ - !ruby/object:Gem::Version
76
+ version: '0'
77
+ requirements: []
78
+ rubyforge_project:
79
+ rubygems_version: 1.8.23
80
+ signing_key:
81
+ specification_version: 3
82
+ summary: Wrapper to Google's civic info API
83
+ test_files:
84
+ - spec/spec_helper.rb
85
+ - spec/unit/civic_info_spec.rb