civic_info 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +2 -1
- data/Gemfile.lock +7 -2
- data/README.mkd +17 -0
- data/civic_info.gemspec +3 -2
- data/lib/civic_info.rb +11 -7
- data/spec/unit/civic_info_spec.rb +1 -1
- metadata +19 -2
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
civic_info (
|
4
|
+
civic_info (1.0.0)
|
5
5
|
active_support
|
6
6
|
httparty
|
7
7
|
|
@@ -12,11 +12,15 @@ GEM
|
|
12
12
|
activesupport (= 3.0.0)
|
13
13
|
activesupport (3.0.0)
|
14
14
|
diff-lcs (1.1.3)
|
15
|
+
faraday (0.8.4)
|
16
|
+
multipart-post (~> 1.1)
|
15
17
|
httparty (0.9.0)
|
16
18
|
multi_json (~> 1.0)
|
17
19
|
multi_xml
|
20
|
+
json (1.6.1)
|
18
21
|
multi_json (1.3.7)
|
19
22
|
multi_xml (0.5.1)
|
23
|
+
multipart-post (1.1.5)
|
20
24
|
rspec (2.11.0)
|
21
25
|
rspec-core (~> 2.11.0)
|
22
26
|
rspec-expectations (~> 2.11.0)
|
@@ -32,5 +36,6 @@ PLATFORMS
|
|
32
36
|
DEPENDENCIES
|
33
37
|
active_support
|
34
38
|
civic_info!
|
35
|
-
|
39
|
+
faraday
|
40
|
+
json
|
36
41
|
rspec
|
data/README.mkd
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
# Civic Info
|
2
|
+
|
3
|
+
Note: You MUST have a google API key, and it must be set in your environment as GOOGLE_API_KEY
|
4
|
+
|
5
|
+
```
|
6
|
+
gem install civic_info
|
7
|
+
```
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
> ci = CivicInfo.new
|
11
|
+
> ci.elections
|
12
|
+
=> {"kind"=>"civicinfo#electionsQueryResponse", "elections"=>[{"id"=>"2000", "name"=>"VIP Test Election", "
|
13
|
+
electionDay"=>"2013-06-06"}, {"id"=>"4000", "name"=>"U.S. 2012 General Election",
|
14
|
+
"electionDay"=>"2012-11-06"}]}
|
15
|
+
> ci.voter_info(election_id, address_string)
|
16
|
+
=>
|
17
|
+
```
|
data/civic_info.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'civic_info'
|
3
|
-
s.version = '1.0.
|
3
|
+
s.version = '1.0.1'
|
4
4
|
s.date = '2012-11-03'
|
5
5
|
s.summary = 'Wrapper to Google\'s civic info API'
|
6
6
|
s.description = ""
|
@@ -10,6 +10,7 @@ Gem::Specification.new do |s|
|
|
10
10
|
s.test_files = s.files.grep(%r{^(test|spec|features)/})
|
11
11
|
s.homepage = 'http://github.com/joannecheng/civic_info'
|
12
12
|
|
13
|
-
s.add_dependency "
|
13
|
+
s.add_dependency "json"
|
14
|
+
s.add_dependency "faraday"
|
14
15
|
s.add_dependency 'active_support'
|
15
16
|
end
|
data/lib/civic_info.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
|
-
require '
|
1
|
+
require 'faraday'
|
2
|
+
require 'json'
|
2
3
|
require 'active_support/core_ext/hash/indifferent_access'
|
3
4
|
|
4
5
|
class GoogleAPI
|
@@ -6,19 +7,22 @@ class GoogleAPI
|
|
6
7
|
def initialize(api_key, service_name)
|
7
8
|
@api_key = ENV['GOOGLE_API_KEY']
|
8
9
|
@service_url = "https://www.googleapis.com#{service_name}"
|
10
|
+
@conn = Faraday.new(:url => @service_url)
|
9
11
|
end
|
10
12
|
|
11
13
|
def get(call_string)
|
12
|
-
|
14
|
+
JSON.parse(@conn.get("#{call_string}?key=#{@api_key}").body).with_indifferent_access
|
13
15
|
end
|
14
16
|
|
15
|
-
def post(call_string, body
|
16
|
-
|
17
|
-
|
18
|
-
|
17
|
+
def post(call_string, body)
|
18
|
+
response = @conn.post do |conn|
|
19
|
+
conn.url "#{call_string}?key=#{@api_key}"
|
20
|
+
conn.headers['Content-Type'] = 'application/json'
|
21
|
+
conn.body = body.to_json
|
22
|
+
end
|
23
|
+
JSON.parse(response.body).with_indifferent_access
|
19
24
|
end
|
20
25
|
|
21
|
-
|
22
26
|
end
|
23
27
|
|
24
28
|
class CivicInfo
|
@@ -27,7 +27,7 @@ describe CivicInfo do
|
|
27
27
|
describe '#voter_info' do
|
28
28
|
it 'gets voter info' do
|
29
29
|
ci = CivicInfo.new()
|
30
|
-
ci.voter_info(4000, '
|
30
|
+
ci.voter_info(4000, '1263 Pacific Ave. Kansas City KS')[:kind].should == "civicinfo#voterInfoResponse"
|
31
31
|
end
|
32
32
|
end
|
33
33
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: civic_info
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
4
|
+
version: 1.0.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -12,7 +12,23 @@ cert_chain: []
|
|
12
12
|
date: 2012-11-03 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
|
-
name:
|
15
|
+
name: json
|
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: faraday
|
16
32
|
requirement: !ruby/object:Gem::Requirement
|
17
33
|
none: false
|
18
34
|
requirements:
|
@@ -52,6 +68,7 @@ files:
|
|
52
68
|
- .gitignore
|
53
69
|
- Gemfile
|
54
70
|
- Gemfile.lock
|
71
|
+
- README.mkd
|
55
72
|
- civic_info.gemspec
|
56
73
|
- lib/civic_info.rb
|
57
74
|
- spec/spec_helper.rb
|