orias 0.2.0 → 0.3.0

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: af2eff4a09534ebe0f400f5dbece87f1ee526750
4
- data.tar.gz: 1f3a5c974e5e3943d633cfd2ee678e79be8ada9b
3
+ metadata.gz: 7c42f8d5d084f92ee196de4e196d5174eb69e32b
4
+ data.tar.gz: 32a429628c656c9e0eea95092a4f5f36ce3ec333
5
5
  SHA512:
6
- metadata.gz: a3ed5329adbedbbdfe24d9568c54c074841548e95ce7951fa70a6be4d60a5766add809a2ae63e4f9f4fb3248eda907c3b216f95d5c149c0b3a7437cd51df3b18
7
- data.tar.gz: a2ccc2dc4054440621714f553244fb94fc3155af8e028cb39bfc86547455bade0b2ba79ef9f60f70a7b18f7d90700e1ffd3be72c97f264873e1bbf403c062879
6
+ metadata.gz: 47bedfe300e4284c64513793f99e6e15e319e732fbf2beae7018796e360acec02b4f73438119928714ed4df8e88323c8bf803cea75fc17dfa0806ab88e1bf583
7
+ data.tar.gz: c4a74fa5c6edb5ebd752fc9e016d464a2fd213faa3e763338fc480908dc8a43d29a6c90bc9c9d953093ee02ce4e42ea08e3d2123e98d9ac3699f99e19ed0c2ec
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- orias (0.1.0)
4
+ orias (0.2.3)
5
5
  libxml-to-hash
6
6
 
7
7
  GEM
data/lib/orias/client.rb CHANGED
@@ -2,12 +2,13 @@ module Orias
2
2
  # Dedicated to request handling to ORIAS API
3
3
  #
4
4
  class Client < Base
5
- attr_accessor :api_endpoint, :private_key
5
+ attr_accessor :api_endpoint, :per_request, :private_key
6
6
 
7
7
  # Initialize an Orias::Client instance
8
8
  def initialize(attributes = {})
9
9
  super
10
10
  @api_endpoint ||= Orias.configuration.api_endpoint
11
+ @per_request ||= Orias.configuration.per_request
11
12
  @private_key ||= Orias.configuration.private_key
12
13
  end
13
14
  end
@@ -3,13 +3,15 @@ module Orias
3
3
  #
4
4
  class Configuration < Base
5
5
  DEFAULT_API_ENDPOINT = 'https://ws.orias.fr/service?wsdl'.freeze
6
+ DEFAULT_PER_REQUEST = 1000.freeze
6
7
 
7
- attr_accessor :private_key, :api_endpoint
8
+ attr_accessor :private_key, :api_endpoint, :per_request
8
9
 
9
10
  # Initialize an Orias::Configuration instance
10
11
  def initialize(attributes = {})
11
12
  super
12
13
  @api_endpoint ||= DEFAULT_API_ENDPOINT
14
+ @per_request ||= DEFAULT_PER_REQUEST
13
15
  end
14
16
  end
15
17
  end
@@ -6,12 +6,13 @@ module Orias
6
6
  class Response < Base
7
7
  VALID_TYPES = [:intermediary_search].freeze
8
8
 
9
- attr_accessor :type, :raw_response, :raw_hash_response, :results
9
+ attr_accessor :type, :raw, :raw_hash, :results
10
10
 
11
11
  # Initialize an Orias::Response instance
12
12
  def initialize(attributes = {})
13
13
  super
14
- self.process_raw_response!
14
+ self.process_raw_response! if results.nil?
15
+ self.check_type
15
16
  end
16
17
 
17
18
  # Result collections
@@ -54,10 +55,25 @@ module Orias
54
55
 
55
56
  end
56
57
 
58
+ class << self
59
+ def merge(instances)
60
+ if instances.map(&:type).uniq.compact.length != 1
61
+ raise 'Orias::Response - Error merging Orias::Response collection.'
62
+ end
63
+
64
+ self.new(
65
+ raw: instances.map(&:raw),
66
+ raw_hash: instances.map(&:raw_hash),
67
+ results: instances.map(&:results).flatten,
68
+ type: instances.map(&:type).uniq.first
69
+ )
70
+ end
71
+ end
72
+
57
73
  protected
58
74
 
59
75
  def process_raw_response!
60
- self.raw_hash_response = Hash.from_libxml(self.raw_response)['Envelope']['Body']
76
+ self.raw_hash = Hash.from_libxml(self.raw)['Envelope']['Body']
61
77
 
62
78
  if @type == :intermediary_search
63
79
  process_intermediary_search!
@@ -66,13 +82,21 @@ module Orias
66
82
  end
67
83
  end
68
84
 
85
+ def check_type
86
+ raise 'Orias::Response - Wrong type.' unless VALID_TYPES.include?(type)
87
+ end
88
+
69
89
  private
70
90
 
71
91
  def process_intermediary_search!
72
- results_hash = self.raw_hash_response['intermediarySearchResponse']
73
- results_hash = results_hash['intermediaries']['intermediary']
92
+ begin
93
+ results_hash = self.raw_hash['intermediarySearchResponse']
94
+ results_hash = results_hash['intermediaries']['intermediary']
95
+ rescue
96
+ raise 'Orias::Response - API response error.' unless results_hash
97
+ end
74
98
 
75
- @results = results_hash.map do |h|
99
+ @results = [results_hash].flatten.map do |h|
76
100
  Orias::Intermediary.new(h)
77
101
  end
78
102
 
data/lib/orias/search.rb CHANGED
@@ -15,26 +15,30 @@ module Orias
15
15
  end
16
16
 
17
17
  # Alias for #find_by with an :orias type
18
- def find_by_orias(*terms)
18
+ def find_by_orias(terms)
19
19
  find_by(:orias, terms)
20
20
  end
21
21
 
22
22
  # Alias for #find_by with an :siren type
23
- def find_by_siren(*terms)
23
+ def find_by_siren(terms)
24
24
  find_by(:siren, terms)
25
25
  end
26
26
 
27
27
  # Request building for intermediarySearchRequest
28
28
  def find_by(type, terms)
29
- request = Orias::Request.new(
30
- api_endpoint: @client.api_endpoint,
31
- body: raw_find(raw_intermediaries(type, terms))
32
- ).build!
33
-
34
- Orias::Response.new(
35
- type: :intermediary_search,
36
- raw_response: request.response.body
37
- )
29
+ responses = [terms].flatten.each_slice(@client.per_request).map do |term_collection|
30
+ request = Orias::Request.new(
31
+ api_endpoint: @client.api_endpoint,
32
+ body: raw_find(raw_intermediaries(type, term_collection))
33
+ ).build!
34
+
35
+ Orias::Response.new(
36
+ type: :intermediary_search,
37
+ raw: request.response.body
38
+ )
39
+ end
40
+
41
+ Orias::Response.merge(responses)
38
42
  end
39
43
 
40
44
  # Build the raw request body of a search
@@ -86,7 +90,7 @@ module Orias
86
90
 
87
91
  # Check & Set an intermediaries list
88
92
  def set_terms(type, terms)
89
- terms.map!{ |t| t.gsub(/\D/,'') }
93
+ terms.map!{ |t| t.to_s.gsub(/\D/,'') }
90
94
  lgts = terms.map(&:length).uniq
91
95
  valid_lgth = VALID_INTERMEDIARIES_TYPE[type]
92
96
 
data/lib/orias/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Orias
2
- VERSION = '0.2.0'.freeze
2
+ VERSION = '0.3.0'.freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orias
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - 01max
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-24 00:00:00.000000000 Z
11
+ date: 2019-01-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: libxml-to-hash