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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: f4b11cfc5030aaa88eda0379f0371d88f9f9c85704c5178c529245763fe61a34
4
- data.tar.gz: 3c1f2659cccac88e8a0264640d4d50095923eb4f1fe5575787c573c3db306d6f
3
+ metadata.gz: f191f4b57c93f590de515f14419f641c5f0969c61c3530d39fb36e273c69908f
4
+ data.tar.gz: 135820cdc370842bff9591be7811bac3c4e8803a20c897533ed54b46bc9d42f4
5
5
  SHA512:
6
- metadata.gz: 7e277a8058ce64b1456154e5e86ca5b8091be1e5491e3d153ccd8e22526ec0d8c425c57cd2e6b5389abb27bd38e614a646cf2d04454e47d60a3280aa6534ac3e
7
- data.tar.gz: cebc4524362c82d29238b3421757c96852bec0fe7f41d8f8038589b1b534c8460a9b4bcc7d92452147ef186f87a670ba0ec8999bc6ff3991efa7ffb7426857eb
6
+ metadata.gz: 5a6aa69986eada23823eff9aff7487de11278f4d4db96fad284d27f48062a547c5d660bdcd3a2687707d16135057e3267ae646aa1e998d3b9e07ea4c664a189f
7
+ data.tar.gz: 547b36d74bb0569010cf4efc981076e4e1a57002d4e97280910486d465005c5e158afd26e277d94d371cc959af81f373b6aa962f9d437a4ed88aa7990e09b1c0
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- civic_information (1.0.1)
4
+ civic_information (1.1.0)
5
5
  httparty (= 0.18.0)
6
6
 
7
7
  GEM
@@ -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(officials:)
18
- @officials = officials
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 self.build_officials(officials_response)
24
- officials_response.
25
- map { |official| RepresentativesResource::Official.new(official) }
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, :urls, :channels,
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
@@ -1,3 +1,3 @@
1
1
  module CivicInformation
2
- VERSION = "1.0.1"
2
+ VERSION = "1.1.0"
3
3
  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.1
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-06-28 00:00:00.000000000 Z
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