get-your-rep 1.2.0.1 → 1.3.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: c62ff3b5225ccdada8d870dad064b1ed6f536ffa
4
- data.tar.gz: 236aac95d139f19fe6b5f0132a76d5d1482bee6c
3
+ metadata.gz: 52bf8ddb67a097e898e730ca14c1e96704bcc5bd
4
+ data.tar.gz: a0323f417342ec9ddc7857768b56cb069da3af9a
5
5
  SHA512:
6
- metadata.gz: 853ec671149665300a3c8ed354887300d7082954c3f2e44206450f592ff411ca385c41486ea516877c8c20e36ec28b511fcb4839231d343aeaaeed75de9febd5
7
- data.tar.gz: b6e7d179ef1476893011b85affba07dccb0cbcbc12879c177d0d7baf71196b946f001cad626cf13ca986522de923f53ee30d76425a4563d134ac5a1f3c1a50c8
6
+ metadata.gz: 95d92d07420e9fc505f703e5da1902c32597a5587a3623eaf68a4994efc527808ce80970e6626fea9aa57018209987d171e55f88d7683bd14b2e5d391fe408fc
7
+ data.tar.gz: 79e7bfd8d754f4de15916c072c13dbdbdac884babfefb2285ff3d5269d03cc703c2f29370a1716b40199c918e3fc2fe69f522480050a24aaa39c32da0d41e340
data/lib/get-your-rep.rb CHANGED
@@ -15,7 +15,7 @@ class GetYourRep
15
15
  # Supported options for :role are "representative"(default), "senator", "executive" and "vice executive".
16
16
  def self.now(address, level: 'national', role: 'representative')
17
17
  @address = voter_address(address)
18
- @api_key = ENV['GOOGLE_API_KEY']
18
+ @api_key ||= ENV['GOOGLE_API_KEY']
19
19
  @level = level
20
20
  @role = role
21
21
  @response = get_rep
@@ -24,11 +24,22 @@ class GetYourRep
24
24
  return Delegation.new
25
25
  elsif @response['error']
26
26
  puts 'Error message received. Confirm and re-enter your address and check your parameters.'
27
+ puts @response
27
28
  return Delegation.new
28
29
  end
29
30
  parse_rep
30
31
  parse_channels if @officials.any? { |official| official['channels'] }
31
- @reps
32
+ @delegation
33
+ end
34
+
35
+ #Returns reps in Congress and State Legislature, plus Governor and Lieutenant Governor.
36
+ def self.all(address)
37
+ @reps = now(address, level: 'national', role: 'representative')
38
+ @reps << now(address, level: 'national', role: 'senator')
39
+ @reps << now(address, level: 'state', role: 'representative')
40
+ @reps << now(address, level: 'state', role: 'senator')
41
+ @reps << now(address, level: 'state', role: 'executive')
42
+ @reps << now(address, level: 'state', role: 'vice executive')
32
43
  end
33
44
 
34
45
  # Parses a String address and prepares for an HTTP request. Accepts Strings and Integers as args.
@@ -64,26 +75,26 @@ class GetYourRep
64
75
  # Parses the JSON response and assembles it into a Delegation object, except for social media attributes,
65
76
  # which are handles by ::parse_channels.
66
77
  def self.parse_rep
67
- @reps = Delegation.new
78
+ @delegation = Delegation.new
68
79
  @officials = @response['officials']
69
80
 
70
81
  i = 0
71
82
  @officials.each do |official|
72
- @reps[i] = {}
83
+ @delegation[i] = {}
73
84
 
74
- @reps[i][:name] = official['name']
75
- @reps[i][:office] = @response['offices'].first['name']
76
- @reps[i][:party] = official['party']
77
- @reps[i][:phone] = official['phones'].first
78
- @reps[i][:address_1] = official['address'].first['line1']
79
- @reps[i][:address_2] = official['address'].first['line2']
80
- @reps[i][:address_3] = official['address'].first['line3']
81
- @reps[i][:address_city] = official['address'].first['city'].capitalize
82
- @reps[i][:address_state] = official['address'].first['state']
83
- @reps[i][:address_zip] = official['address'].first['zip']
84
- @reps[i][:email] = official['emails'] if official['emails']
85
- @reps[i][:url] = official['urls'].first
86
- @reps[i][:photo] = official['photoUrl']
85
+ @delegation[i][:name] = official['name']
86
+ @delegation[i][:office] = @response['offices'].first['name']
87
+ @delegation[i][:party] = official['party']
88
+ @delegation[i][:phone] = official['phones'].first
89
+ @delegation[i][:address_1] = official['address'].first['line1']
90
+ @delegation[i][:address_2] = official['address'].first['line2']
91
+ @delegation[i][:address_3] = official['address'].first['line3']
92
+ @delegation[i][:address_city] = official['address'].first['city'].capitalize
93
+ @delegation[i][:address_state] = official['address'].first['state']
94
+ @delegation[i][:address_zip] = official['address'].first['zip']
95
+ @delegation[i][:email] = official['emails'] if official['emails']
96
+ @delegation[i][:url] = official['urls'].first
97
+ @delegation[i][:photo] = official['photoUrl']
87
98
  i += 1
88
99
  end
89
100
  end
@@ -94,7 +105,7 @@ class GetYourRep
94
105
  @officials.each do |official|
95
106
  next unless official['channels']
96
107
  official['channels'].each do |channel|
97
- @reps[i][channel['type'].downcase.to_sym] = channel['id']
108
+ @delegation[i][channel['type'].downcase.to_sym] = channel['id']
98
109
  end
99
110
  i += 1
100
111
  end
@@ -21,7 +21,7 @@ class Delegation < Array
21
21
 
22
22
  # Collects the first names of every rep in the Delegation.
23
23
  def first_names
24
- self.map { |rep| rep[:name].split[0..-2].join(' ')}
24
+ self.map { |rep| rep[:name].split[0..-2].join(' ') }
25
25
  end
26
26
 
27
27
  # Collects the last names of every rep in the Delegation.
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: get-your-rep
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.2.0.1
4
+ version: 1.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - msimonborg