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 +4 -4
- data/lib/get-your-rep.rb +29 -18
- data/lib/get-your-rep/delegation.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 52bf8ddb67a097e898e730ca14c1e96704bcc5bd
|
4
|
+
data.tar.gz: a0323f417342ec9ddc7857768b56cb069da3af9a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
|
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
|
-
@
|
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
|
-
@
|
78
|
+
@delegation = Delegation.new
|
68
79
|
@officials = @response['officials']
|
69
80
|
|
70
81
|
i = 0
|
71
82
|
@officials.each do |official|
|
72
|
-
@
|
83
|
+
@delegation[i] = {}
|
73
84
|
|
74
|
-
@
|
75
|
-
@
|
76
|
-
@
|
77
|
-
@
|
78
|
-
@
|
79
|
-
@
|
80
|
-
@
|
81
|
-
@
|
82
|
-
@
|
83
|
-
@
|
84
|
-
@
|
85
|
-
@
|
86
|
-
@
|
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
|
-
@
|
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.
|