civic_information 1.0.1 → 1.1.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/Gemfile.lock +1 -1
- data/lib/civic_information.rb +2 -0
- data/lib/civic_information/models/representatives_resource.rb +34 -9
- data/lib/civic_information/models/representatives_resource/division.rb +24 -0
- data/lib/civic_information/models/representatives_resource/office.rb +35 -0
- data/lib/civic_information/models/representatives_resource/official.rb +15 -3
- data/lib/civic_information/version.rb +1 -1
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f191f4b57c93f590de515f14419f641c5f0969c61c3530d39fb36e273c69908f
|
|
4
|
+
data.tar.gz: 135820cdc370842bff9591be7811bac3c4e8803a20c897533ed54b46bc9d42f4
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 5a6aa69986eada23823eff9aff7487de11278f4d4db96fad284d27f48062a547c5d660bdcd3a2687707d16135057e3267ae646aa1e998d3b9e07ea4c664a189f
|
|
7
|
+
data.tar.gz: 547b36d74bb0569010cf4efc981076e4e1a57002d4e97280910486d465005c5e158afd26e277d94d371cc959af81f373b6aa962f9d437a4ed88aa7990e09b1c0
|
data/Gemfile.lock
CHANGED
data/lib/civic_information.rb
CHANGED
|
@@ -2,6 +2,8 @@ require "httparty"
|
|
|
2
2
|
require "civic_information/version"
|
|
3
3
|
require "civic_information/configuration"
|
|
4
4
|
require "civic_information/models/representatives_resource"
|
|
5
|
+
require "civic_information/models/representatives_resource/division"
|
|
6
|
+
require "civic_information/models/representatives_resource/office"
|
|
5
7
|
require "civic_information/models/representatives_resource/official"
|
|
6
8
|
require "civic_information/models/representatives_resource/channel"
|
|
7
9
|
require "civic_information/models/representatives_resource/address"
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
module CivicInformation
|
|
2
2
|
class RepresentativesResource
|
|
3
|
-
attr_accessor :officials
|
|
3
|
+
attr_accessor :divisions, :offices, :officials
|
|
4
4
|
|
|
5
5
|
def self.where(address: nil, roles: nil)
|
|
6
6
|
response = CivicInformation.get "/representatives", query: {
|
|
@@ -9,20 +9,45 @@ module CivicInformation
|
|
|
9
9
|
roles: roles
|
|
10
10
|
}.delete_if { |k, v| v.nil? }
|
|
11
11
|
|
|
12
|
-
self.new
|
|
13
|
-
officials: build_officials(response.parsed_response["officials"] || [])
|
|
14
|
-
)
|
|
12
|
+
self.new response: response
|
|
15
13
|
end
|
|
16
14
|
|
|
17
|
-
def initialize(
|
|
18
|
-
@
|
|
15
|
+
def initialize(response:)
|
|
16
|
+
@divisions = build_divisions(response.parsed_response["divisions"] || [])
|
|
17
|
+
@offices = build_offices(response.parsed_response["offices"] || [])
|
|
18
|
+
@officials = build_officials(response.parsed_response["officials"] || [])
|
|
19
19
|
end
|
|
20
20
|
|
|
21
21
|
private
|
|
22
22
|
|
|
23
|
-
def
|
|
24
|
-
|
|
25
|
-
|
|
23
|
+
def build_divisions(divisions_response)
|
|
24
|
+
divisions_response.map do |open_civic_data_id, division|
|
|
25
|
+
RepresentativesResource::Division.new(
|
|
26
|
+
open_civic_data_id: open_civic_data_id,
|
|
27
|
+
division_json: division,
|
|
28
|
+
parent_resource_id: self.object_id
|
|
29
|
+
)
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def build_offices(offices_response)
|
|
34
|
+
offices_response.each_with_index.map do |office, result_index|
|
|
35
|
+
RepresentativesResource::Office.new(
|
|
36
|
+
result_index: result_index,
|
|
37
|
+
office_json: office,
|
|
38
|
+
parent_resource_id: self.object_id
|
|
39
|
+
)
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
def build_officials(officials_response)
|
|
44
|
+
officials_response.each_with_index.map do |official, result_index|
|
|
45
|
+
RepresentativesResource::Official.new(
|
|
46
|
+
result_index: result_index,
|
|
47
|
+
official_json: official,
|
|
48
|
+
parent_resource_id: self.object_id
|
|
49
|
+
)
|
|
50
|
+
end
|
|
26
51
|
end
|
|
27
52
|
end
|
|
28
53
|
end
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
module CivicInformation
|
|
2
|
+
class RepresentativesResource::Division
|
|
3
|
+
attr_accessor :open_civic_data_id, :also_known_as, :name
|
|
4
|
+
|
|
5
|
+
def initialize(open_civic_data_id:, division_json:, parent_resource_id:)
|
|
6
|
+
@parent_resource_id = parent_resource_id
|
|
7
|
+
@open_civic_data_id = open_civic_data_id
|
|
8
|
+
@also_known_as = division_json['alsoKnownAs'] || []
|
|
9
|
+
@name = division_json['name']
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
def offices
|
|
13
|
+
parent_resource.offices.select do |office|
|
|
14
|
+
office.division_id == open_civic_data_id
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
private
|
|
19
|
+
|
|
20
|
+
def parent_resource
|
|
21
|
+
ObjectSpace._id2ref(@parent_resource_id)
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
module CivicInformation
|
|
2
|
+
class RepresentativesResource::Office
|
|
3
|
+
attr_accessor :result_index, :division_id, :levels, :name,
|
|
4
|
+
:official_indices, :roles, :sources
|
|
5
|
+
|
|
6
|
+
def initialize(result_index:, office_json:, parent_resource_id:)
|
|
7
|
+
@parent_resource_id = parent_resource_id
|
|
8
|
+
@result_index = result_index
|
|
9
|
+
@division_id = office_json['divisionId']
|
|
10
|
+
@levels = office_json['levels'] || []
|
|
11
|
+
@name = office_json['name']
|
|
12
|
+
@roles = office_json['roles'] || []
|
|
13
|
+
@sources = office_json['sources'] || []
|
|
14
|
+
@official_indices = office_json['officialIndices'] || []
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def officials
|
|
18
|
+
parent_resource.officials.select do |official|
|
|
19
|
+
@official_indices.include? official.result_index
|
|
20
|
+
end
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def division
|
|
24
|
+
parent_resource.divisions.find do |division|
|
|
25
|
+
division.open_civic_data_id == division_id
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
private
|
|
30
|
+
|
|
31
|
+
def parent_resource
|
|
32
|
+
ObjectSpace._id2ref(@parent_resource_id)
|
|
33
|
+
end
|
|
34
|
+
end
|
|
35
|
+
end
|
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
module CivicInformation
|
|
2
2
|
class RepresentativesResource::Official
|
|
3
|
-
attr_accessor :name, :photo_url, :party, :phones, :emails,
|
|
4
|
-
:addresses
|
|
3
|
+
attr_accessor :result_index, :name, :photo_url, :party, :phones, :emails,
|
|
4
|
+
:urls, :channels, :addresses
|
|
5
5
|
|
|
6
|
-
def initialize(official_json)
|
|
6
|
+
def initialize(result_index:, official_json:, parent_resource_id:)
|
|
7
|
+
@parent_resource_id = parent_resource_id
|
|
8
|
+
@result_index = result_index
|
|
7
9
|
@name = official_json["name"]
|
|
8
10
|
@photo_url = official_json["photoUrl"]
|
|
9
11
|
@party = official_json["party"]
|
|
@@ -14,6 +16,12 @@ module CivicInformation
|
|
|
14
16
|
@addresses = build_addresses(official_json["address"] || [])
|
|
15
17
|
end
|
|
16
18
|
|
|
19
|
+
def offices
|
|
20
|
+
parent_resource.offices.select do |office|
|
|
21
|
+
office.official_indices.include? result_index
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
|
|
17
25
|
private
|
|
18
26
|
|
|
19
27
|
def build_addresses(address_json)
|
|
@@ -23,5 +31,9 @@ module CivicInformation
|
|
|
23
31
|
def build_channels(channels_json)
|
|
24
32
|
channels_json.map { |channel| RepresentativesResource::Channel.new(channel) }
|
|
25
33
|
end
|
|
34
|
+
|
|
35
|
+
def parent_resource
|
|
36
|
+
ObjectSpace._id2ref(@parent_resource_id)
|
|
37
|
+
end
|
|
26
38
|
end
|
|
27
39
|
end
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: civic_information
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 1.0
|
|
4
|
+
version: 1.1.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Will Olson
|
|
8
8
|
autorequire:
|
|
9
9
|
bindir: exe
|
|
10
10
|
cert_chain: []
|
|
11
|
-
date: 2020-
|
|
11
|
+
date: 2020-07-04 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: bundler
|
|
@@ -160,6 +160,8 @@ files:
|
|
|
160
160
|
- lib/civic_information/models/representatives_resource.rb
|
|
161
161
|
- lib/civic_information/models/representatives_resource/address.rb
|
|
162
162
|
- lib/civic_information/models/representatives_resource/channel.rb
|
|
163
|
+
- lib/civic_information/models/representatives_resource/division.rb
|
|
164
|
+
- lib/civic_information/models/representatives_resource/office.rb
|
|
163
165
|
- lib/civic_information/models/representatives_resource/official.rb
|
|
164
166
|
- lib/civic_information/version.rb
|
|
165
167
|
homepage: https://github.com/frankolson/ruby-civic-information
|