get-your-rep 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/get-your-rep.rb +66 -0
  3. metadata +73 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 35f7a79adeb753238b67448e1da5d32eb3d2a5b2
4
+ data.tar.gz: ab624b513897130812768cc4109b2750319847b5
5
+ SHA512:
6
+ metadata.gz: 8d7f613a4be1746682ef03f881ceca63fa1ac28b5d8a5a48e4866fc0d45bace462b29d5069918e85d10cae9a4e5d5b000cadd4cdd400380767dde75f20c01e89
7
+ data.tar.gz: be3da81d72c888811efc2547c8cea036dce710dacc8a88bd616942ccd524ab4d5d6241deac97a84f78f02c7bfa51f516ec3aae6143f9bf535258d76b4489bb39
@@ -0,0 +1,66 @@
1
+ require 'pry'
2
+ require 'httparty'
3
+
4
+ class GetYourRep
5
+ attr_accessor :rep, :rep_info, :address, :api_key, :level, :role
6
+
7
+ def self.now(address, api_key, level = 'national', role = 'representative')
8
+ @address = voter_address(address)
9
+ @api_key = api_key
10
+ @level = level
11
+ @role = role
12
+ @rep = get_rep
13
+ if @rep.empty?
14
+ puts 'Could not find your rep.'
15
+ return nil
16
+ end
17
+ parse_rep
18
+ parse_channels
19
+ @rep_info
20
+ end
21
+
22
+ def self.voter_address(address)
23
+ address.tr(',', '').split.join('%20')
24
+ end
25
+
26
+ def self.get_rep
27
+ level = case @level
28
+ when 'national'
29
+ "country"
30
+ when 'state'
31
+ "administrativeArea1"
32
+ end
33
+
34
+ role = case @role
35
+ when 'representative'
36
+ 'legislatorLowerBody'
37
+ when 'senator'
38
+ 'legislatorUpperBody'
39
+ end
40
+ url = "https://www.googleapis.com/civicinfo/v2/representatives?address=#{@address}%20&includeOffices=true&levels=#{level}&roles=#{role}&fields=offices%2Cofficials&key=#{@api_key}"
41
+ HTTParty.get(url).parsed_response
42
+ end
43
+
44
+ def self.parse_rep
45
+ @rep_info = {
46
+ 'office' => @rep['offices'].first['name'],
47
+ 'name' => @rep['officials'].first['name'],
48
+ 'party' => @rep['officials'].first['party'],
49
+ 'phone' => @rep['officials'].first['phones'].first,
50
+ 'address_1' => @rep['officials'].first['address'].first['line1'],
51
+ 'address_2' => @rep['officials'].first['address'].first['line2'],
52
+ 'address_3' => @rep['officials'].first['address'].first['line3'],
53
+ 'address_city' => @rep['officials'].first['address'].first['city'].capitalize,
54
+ 'address_state' => @rep['officials'].first['address'].first['state'],
55
+ 'address_zip' => @rep['officials'].first['address'].first['zip'],
56
+ 'url' => @rep['officials'].first['urls'].first,
57
+ 'photo' => @rep['officials'].first['photoUrl'],
58
+ }
59
+ end
60
+
61
+ def self.parse_channels
62
+ @rep['officials'].first['channels'].each do |channel|
63
+ @rep_info[channel['type'].downcase] = channel['id']
64
+ end
65
+ end
66
+ end
metadata ADDED
@@ -0,0 +1,73 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: get-your-rep
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - msimonborg
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-12-08 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: pry
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Get your rep with Google's Civic Information API with your address and
42
+ API key. Work in progress!!
43
+ email: msimonborg@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - lib/get-your-rep.rb
49
+ homepage: http://rubygems.org/gems/get-your-rep
50
+ licenses:
51
+ - MIT
52
+ metadata: {}
53
+ post_install_message:
54
+ rdoc_options: []
55
+ require_paths:
56
+ - lib
57
+ required_ruby_version: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ required_rubygems_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: '0'
67
+ requirements: []
68
+ rubyforge_project:
69
+ rubygems_version: 2.5.2
70
+ signing_key:
71
+ specification_version: 4
72
+ summary: Get yo' rep!
73
+ test_files: []