parliament-ruby 0.2.0 → 0.2.1
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/.rubocop.yml +1 -1
- data/lib/parliament/decorators/contact_point.rb +16 -0
- data/lib/parliament/decorators/house.rb +15 -0
- data/lib/parliament/decorators/party_membership.rb +2 -2
- data/lib/parliament/decorators/person.rb +1 -1
- data/lib/parliament/decorators/seat_incumbency.rb +2 -2
- data/lib/parliament/no_content_error.rb +9 -0
- data/lib/parliament/request.rb +24 -3
- data/lib/parliament/response.rb +10 -1
- data/lib/parliament/version.rb +1 -1
- data/lib/parliament.rb +1 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff75c94a11fda9a042d4060e4f3c783f69bbed88
|
4
|
+
data.tar.gz: b71eaa4c8b334182313f055214c33956c7f9e01f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 30c5a0245be4f796d5bb21366d83026f0b3d66eb26848d2d38e15919fd0727cd1e9e95a966fc7ea18d0e191bd964f919f766e89821eb63e1d26688580f0af29c
|
7
|
+
data.tar.gz: 2a7e5c955c09ce45f9e792edf9f066dbee83614cdca78dec5f7fa9467d987a69045cc4d4d16cdec91cb90b545ddda6e9c084c2390002c137f17eb70ae8e3c57d
|
data/.rubocop.yml
CHANGED
@@ -4,6 +4,22 @@ module Parliament
|
|
4
4
|
def postal_addresses
|
5
5
|
respond_to?(:contactPointHasPostalAddress) ? contactPointHasPostalAddress : []
|
6
6
|
end
|
7
|
+
|
8
|
+
def email
|
9
|
+
instance_variable_get('@email'.to_sym).nil? ? '' : instance_variable_get('@email'.to_sym)
|
10
|
+
end
|
11
|
+
|
12
|
+
def phone_number
|
13
|
+
respond_to?(:phoneNumber) ? phoneNumber : ''
|
14
|
+
end
|
15
|
+
|
16
|
+
def fax_number
|
17
|
+
respond_to?(:faxNumber) ? faxNumber : ''
|
18
|
+
end
|
19
|
+
|
20
|
+
def person
|
21
|
+
respond_to?(:contactPointHasPerson) ? contactPointHasPerson : []
|
22
|
+
end
|
7
23
|
end
|
8
24
|
end
|
9
25
|
end
|
@@ -4,6 +4,21 @@ module Parliament
|
|
4
4
|
def name
|
5
5
|
respond_to?(:houseName) ? houseName : ''
|
6
6
|
end
|
7
|
+
|
8
|
+
def seat_incumbencies
|
9
|
+
return @seat_incumbencies unless @seat_incumbencies.nil?
|
10
|
+
|
11
|
+
seat_incumbencies = []
|
12
|
+
seats.each do |seat|
|
13
|
+
seat_incumbencies << seat.seat_incumbencies
|
14
|
+
end
|
15
|
+
|
16
|
+
@seat_incumbencies = seat_incumbencies.flatten.uniq
|
17
|
+
end
|
18
|
+
|
19
|
+
def seats
|
20
|
+
respond_to?(:houseHasHouseSeat) ? houseHasHouseSeat : []
|
21
|
+
end
|
7
22
|
end
|
8
23
|
end
|
9
24
|
end
|
@@ -6,11 +6,11 @@ module Parliament
|
|
6
6
|
end
|
7
7
|
|
8
8
|
def start_date
|
9
|
-
respond_to?(:partyMembershipStartDate) ? partyMembershipStartDate :
|
9
|
+
respond_to?(:partyMembershipStartDate) ? DateTime.parse(partyMembershipStartDate) : nil
|
10
10
|
end
|
11
11
|
|
12
12
|
def end_date
|
13
|
-
respond_to?(:partyMembershipEndDate) ? partyMembershipEndDate :
|
13
|
+
respond_to?(:partyMembershipEndDate) ? DateTime.parse(partyMembershipEndDate) : nil
|
14
14
|
end
|
15
15
|
end
|
16
16
|
end
|
@@ -2,11 +2,11 @@ module Parliament
|
|
2
2
|
module Decorators
|
3
3
|
module SeatIncumbency
|
4
4
|
def start_date
|
5
|
-
respond_to?(:seatIncumbencyStartDate) ? seatIncumbencyStartDate :
|
5
|
+
respond_to?(:seatIncumbencyStartDate) ? DateTime.parse(seatIncumbencyStartDate) : nil
|
6
6
|
end
|
7
7
|
|
8
8
|
def end_date
|
9
|
-
respond_to?(:seatIncumbencyEndDate) ? seatIncumbencyEndDate :
|
9
|
+
respond_to?(:seatIncumbencyEndDate) ? DateTime.parse(seatIncumbencyEndDate) : nil
|
10
10
|
end
|
11
11
|
|
12
12
|
def seat
|
data/lib/parliament/request.rb
CHANGED
@@ -22,17 +22,38 @@ module Parliament
|
|
22
22
|
end
|
23
23
|
|
24
24
|
def get
|
25
|
-
|
25
|
+
net_response = Net::HTTP.get_response(URI(api_endpoint))
|
26
26
|
|
27
|
-
|
28
|
-
|
27
|
+
handle_errors(net_response)
|
28
|
+
|
29
|
+
build_parliament_response(net_response)
|
30
|
+
end
|
29
31
|
|
32
|
+
def build_parliament_response(response)
|
30
33
|
objects = Grom::Reader.new(response.body).objects
|
31
34
|
objects.map { |object| assign_decorator(object) }
|
32
35
|
|
33
36
|
Parliament::Response.new(objects)
|
34
37
|
end
|
35
38
|
|
39
|
+
def handle_errors(response)
|
40
|
+
handle_not_found_error(response)
|
41
|
+
handle_server_error(response)
|
42
|
+
handle_no_content_error(response)
|
43
|
+
end
|
44
|
+
|
45
|
+
def handle_server_error(response)
|
46
|
+
raise StandardError, 'This is a HTTPServerError' if response.is_a?(Net::HTTPServerError)
|
47
|
+
end
|
48
|
+
|
49
|
+
def handle_not_found_error(response)
|
50
|
+
raise StandardError, 'This is a HTTPClientError' if response.is_a?(Net::HTTPClientError)
|
51
|
+
end
|
52
|
+
|
53
|
+
def handle_no_content_error(response)
|
54
|
+
raise Parliament::NoContentError if response.code == '204'
|
55
|
+
end
|
56
|
+
|
36
57
|
def assign_decorator(object)
|
37
58
|
object_type = Grom::Helper.get_id(object.type)
|
38
59
|
return object unless Parliament::Decorators.constants.include?(object_type.to_sym)
|
data/lib/parliament/response.rb
CHANGED
@@ -21,9 +21,18 @@ module Parliament
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
+
result = build_responses(filtered_objects)
|
25
|
+
|
26
|
+
types.size == 1 ? result.first : result
|
27
|
+
end
|
28
|
+
|
29
|
+
def build_responses(filtered_objects)
|
30
|
+
result = []
|
31
|
+
|
24
32
|
filtered_objects.each do |objects|
|
25
|
-
Parliament::Response.new(objects)
|
33
|
+
result << Parliament::Response.new(objects)
|
26
34
|
end
|
35
|
+
result
|
27
36
|
end
|
28
37
|
end
|
29
38
|
end
|
data/lib/parliament/version.rb
CHANGED
data/lib/parliament.rb
CHANGED
@@ -4,6 +4,7 @@ require 'grom'
|
|
4
4
|
require 'parliament/version'
|
5
5
|
require 'parliament/request'
|
6
6
|
require 'parliament/response'
|
7
|
+
require 'parliament/no_content_error'
|
7
8
|
|
8
9
|
# require all the decorators
|
9
10
|
Dir[File.join(File.dirname(__FILE__), 'parliament/decorators', '*.rb')].each { |decorator| require decorator }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: parliament-ruby
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Matt Rayner
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2017-02-
|
11
|
+
date: 2017-02-14 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: grom
|
@@ -183,6 +183,7 @@ files:
|
|
183
183
|
- lib/parliament/decorators/person.rb
|
184
184
|
- lib/parliament/decorators/postal_address.rb
|
185
185
|
- lib/parliament/decorators/seat_incumbency.rb
|
186
|
+
- lib/parliament/no_content_error.rb
|
186
187
|
- lib/parliament/request.rb
|
187
188
|
- lib/parliament/response.rb
|
188
189
|
- lib/parliament/version.rb
|