parliament-ruby 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fbf1462f8c45035775444da6cbb76f8dfd49a905
4
- data.tar.gz: 3fc840d1285f95774e4c1d6b7bc496707dd1ed5f
3
+ metadata.gz: ff75c94a11fda9a042d4060e4f3c783f69bbed88
4
+ data.tar.gz: b71eaa4c8b334182313f055214c33956c7f9e01f
5
5
  SHA512:
6
- metadata.gz: 161013d67753e2b47ce04633355047795bad91d3505513c18afe3ba6ba670ac24e94cde0adc6370037de8cc8dfcb4ac7dfc064b706fa29ee8d3a743522fd0b6f
7
- data.tar.gz: 0015226bef6ee2c28a9f4908fcb3166422bd28ebe300f9447f3bf2d21e78cdccf7986cfae1e27ee7e1880df14e953c38b7e93790d788afd59eeb438c529cd0df
6
+ metadata.gz: 30c5a0245be4f796d5bb21366d83026f0b3d66eb26848d2d38e15919fd0727cd1e9e95a966fc7ea18d0e191bd964f919f766e89821eb63e1d26688580f0af29c
7
+ data.tar.gz: 2a7e5c955c09ce45f9e792edf9f066dbee83614cdca78dec5f7fa9467d987a69045cc4d4d16cdec91cb90b545ddda6e9c084c2390002c137f17eb70ae8e3c57d
data/.rubocop.yml CHANGED
@@ -53,5 +53,5 @@ AllCops:
53
53
  Exclude:
54
54
  - '*.gemspec'
55
55
  - 'vendor/**/*'
56
- - 'spec/fixtures/**/*'
56
+ - 'spec/**/*'
57
57
  - 'tmp/**/*'
@@ -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
@@ -14,7 +14,7 @@ module Parliament
14
14
  end
15
15
 
16
16
  def date_of_birth
17
- respond_to?(:personDateOfBirth) ? personDateOfBirth : ''
17
+ respond_to?(:personDateOfBirth) ? DateTime.parse(personDateOfBirth) : nil
18
18
  end
19
19
 
20
20
  def full_name
@@ -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
@@ -0,0 +1,9 @@
1
+ module Parliament
2
+ class NoContentError < StandardError
3
+ attr_reader :message
4
+
5
+ def initialize
6
+ @message = 'No content'
7
+ end
8
+ end
9
+ end
@@ -22,17 +22,38 @@ module Parliament
22
22
  end
23
23
 
24
24
  def get
25
- response = Net::HTTP.get_response(URI(api_endpoint))
25
+ net_response = Net::HTTP.get_response(URI(api_endpoint))
26
26
 
27
- raise StandardError, 'This is a HTTPClientError' if response.is_a?(Net::HTTPClientError)
28
- raise StandardError, 'This is a HTTPServerError' if response.is_a?(Net::HTTPServerError)
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)
@@ -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
@@ -1,3 +1,3 @@
1
1
  module Parliament
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.2.1'.freeze
3
3
  end
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.0
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-08 00:00:00.000000000 Z
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