orias 0.1.0 → 0.2.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: 063aaf0efbd771a7a33f9446d4ae3c362a568460
4
- data.tar.gz: 4cacdf0afca699c83942b5e08b307e945eeb231d
3
+ metadata.gz: af2eff4a09534ebe0f400f5dbece87f1ee526750
4
+ data.tar.gz: 1f3a5c974e5e3943d633cfd2ee678e79be8ada9b
5
5
  SHA512:
6
- metadata.gz: 37c47e18ea995947e2a8d8ca7927efa500144737fef2aa1a9693623ab216ed0a0ce944e8406798848d8a8f40efdb63a7e8c026f287d0db4214e670fd085d4aa8
7
- data.tar.gz: c9c19af1c4ca0bb1a4ae1ea0ca03cbb7e1c941cd8b744e5a0a9e856d900b4d1f1e1e7551bb82be484af61585ef54c37fe78c3a44b0470e84dc86b0d12dd7623e
6
+ metadata.gz: a3ed5329adbedbbdfe24d9568c54c074841548e95ce7951fa70a6be4d60a5766add809a2ae63e4f9f4fb3248eda907c3b216f95d5c149c0b3a7437cd51df3b18
7
+ data.tar.gz: a2ccc2dc4054440621714f553244fb94fc3155af8e028cb39bfc86547455bade0b2ba79ef9f60f70a7b18f7d90700e1ffd3be72c97f264873e1bbf403c062879
data/.rubocop.yml ADDED
@@ -0,0 +1,5 @@
1
+ Metrics/BlockLength:
2
+ Exclude:
3
+ - 'Rakefile'
4
+ - '**/*.rake'
5
+ - 'spec/**/*.rb'
data/Gemfile.lock CHANGED
@@ -2,17 +2,26 @@ PATH
2
2
  remote: .
3
3
  specs:
4
4
  orias (0.1.0)
5
+ libxml-to-hash
5
6
 
6
7
  GEM
7
8
  remote: https://rubygems.org/
8
9
  specs:
9
10
  ansi (1.5.0)
10
11
  ast (2.4.0)
12
+ concurrent-ruby (1.1.4)
11
13
  diff-lcs (1.3)
12
14
  docile (1.3.1)
15
+ faker (1.9.1)
16
+ i18n (>= 0.7)
13
17
  hirb (0.7.3)
18
+ i18n (1.5.1)
19
+ concurrent-ruby (~> 1.0)
14
20
  jaro_winkler (1.5.2)
15
21
  json (2.1.0)
22
+ libxml-ruby (3.1.0)
23
+ libxml-to-hash (0.2.1)
24
+ libxml-ruby
16
25
  parallel (1.12.1)
17
26
  parser (2.5.3.0)
18
27
  ast (~> 2.4.0)
@@ -57,6 +66,7 @@ PLATFORMS
57
66
 
58
67
  DEPENDENCIES
59
68
  bundler (~> 1.16)
69
+ faker (~> 1.9)
60
70
  orias!
61
71
  rake (~> 10.0)
62
72
  rspec (~> 3.0)
data/README.md CHANGED
@@ -1,6 +1,7 @@
1
1
  # Orias
2
2
 
3
3
 
4
+ [![Gem Version](https://badge.fury.io/rb/orias.svg)](https://badge.fury.io/rb/orias)
4
5
  [![Build Status](https://travis-ci.org/01max/orias.svg?branch=master)](https://travis-ci.org/01max/orias)
5
6
  [![Maintainability](https://api.codeclimate.com/v1/badges/634c92245aefc4bba229/maintainability)](https://codeclimate.com/github/01max/orias/maintainability)
6
7
  [![Test Coverage](https://api.codeclimate.com/v1/badges/634c92245aefc4bba229/test_coverage)](https://codeclimate.com/github/01max/orias/test_coverage)
data/Rakefile CHANGED
@@ -1,6 +1,8 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
1
+ require 'bundler/gem_tasks'
2
+ require 'rspec/core/rake_task'
3
+ require 'rubocop/rake_task'
3
4
 
4
5
  RSpec::Core::RakeTask.new(:spec)
6
+ RuboCop::RakeTask.new(:rubocop)
5
7
 
6
- task :default => :spec
8
+ task default: %i[spec rubocop]
data/bin/console CHANGED
@@ -1,14 +1,7 @@
1
1
  #!/usr/bin/env ruby
2
2
 
3
- require "bundler/setup"
4
- require "orias"
3
+ require 'bundler/setup'
4
+ require 'orias'
5
5
 
6
- # You can add fixtures and/or initialization code here to make experimenting
7
- # with your gem easier. You can also use a different console, if you like.
8
-
9
- # (If you use this, don't forget to add pry to your Gemfile!)
10
- # require "pry"
11
- # Pry.start
12
-
13
- require "irb"
6
+ require 'irb'
14
7
  IRB.start(__FILE__)
data/lib/orias/base.rb ADDED
@@ -0,0 +1,24 @@
1
+ module Orias
2
+ # Base Orias class
3
+ #
4
+ class Base
5
+ def initialize(attributes = {})
6
+ _assign_attributes(attributes)
7
+ end
8
+
9
+ private
10
+
11
+ def _assign_attributes(attributes)
12
+ attributes.each do |key, value|
13
+ _assign_attribute(key, value)
14
+ end
15
+ end
16
+
17
+ def _assign_attribute(key, value)
18
+ setter = :"#{key}="
19
+ raise UnknownAttributeError.new(self, key) unless respond_to?(setter)
20
+
21
+ public_send(setter, value)
22
+ end
23
+ end
24
+ end
@@ -0,0 +1,14 @@
1
+ module Orias
2
+ # Dedicated to request handling to ORIAS API
3
+ #
4
+ class Client < Base
5
+ attr_accessor :api_endpoint, :private_key
6
+
7
+ # Initialize an Orias::Client instance
8
+ def initialize(attributes = {})
9
+ super
10
+ @api_endpoint ||= Orias.configuration.api_endpoint
11
+ @private_key ||= Orias.configuration.private_key
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,15 @@
1
+ module Orias
2
+ # Dedicated to configuration management
3
+ #
4
+ class Configuration < Base
5
+ DEFAULT_API_ENDPOINT = 'https://ws.orias.fr/service?wsdl'.freeze
6
+
7
+ attr_accessor :private_key, :api_endpoint
8
+
9
+ # Initialize an Orias::Configuration instance
10
+ def initialize(attributes = {})
11
+ super
12
+ @api_endpoint ||= DEFAULT_API_ENDPOINT
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,47 @@
1
+ module Orias
2
+ # Dedicated to Orias intermediaries objects handling
3
+ #
4
+ class Intermediary < Base
5
+ attr_accessor :raw, :found, :siren, :orias, :denomination, :registrations
6
+
7
+ alias_method :registration_number, :orias
8
+
9
+ # Initialize an Orias::Intermediary instance
10
+ def initialize(attributes = {})
11
+ @raw = attributes
12
+
13
+ base = @raw.dig('informationBase')
14
+
15
+ @found = base.dig('foundInRegistry') == 'true'
16
+ @siren = base.dig('siren')
17
+ @orias = base.dig('registrationNumber')
18
+ @denomination = base.dig('denomination')
19
+
20
+ raw_registrations = @raw.dig('registrations', 'registration')
21
+ unless raw_registrations.is_a?(Array)
22
+ raw_registrations = [raw_registrations]
23
+ end
24
+
25
+ @registrations = raw_registrations.compact.map do |h|
26
+ Orias::Registration.new(h)
27
+ end
28
+ end
29
+
30
+ def subscribed
31
+ !registrations_with_status('INSCRIT').empty?
32
+ end
33
+
34
+ # Registrations collections
35
+
36
+ def registrations_with_status(status_value)
37
+ @registrations.select do |registration|
38
+ registration.status == status_value
39
+ end
40
+ end
41
+
42
+ private
43
+
44
+ class << self
45
+ end
46
+ end
47
+ end
@@ -0,0 +1,20 @@
1
+ module Orias
2
+ # Dedicated to Orias mandators objects handling
3
+ #
4
+ class Mandator < Base
5
+ attr_accessor :raw, :siren, :denomination
6
+
7
+ # Initialize an Orias::Mandator instance
8
+ def initialize(attributes = {})
9
+ @raw = attributes
10
+
11
+ @siren = @raw.dig('siren')
12
+ @denomination = @raw.dig('denomination')
13
+ end
14
+
15
+ private
16
+
17
+ class << self
18
+ end
19
+ end
20
+ end
@@ -0,0 +1,33 @@
1
+ module Orias
2
+ # Dedicated to Orias registrations objects handling
3
+ #
4
+ class Registration < Base
5
+ attr_accessor :raw, :category_name, :status, :subscribed,
6
+ :registration_date, :collect_funds, :mandators
7
+
8
+ # Initialize an Orias::Registration instance
9
+ def initialize(attributes = {})
10
+ @raw = attributes
11
+
12
+ @category_name = @raw.dig('categoryName')
13
+ @status = @raw.dig('status')
14
+ @subscribed = @status == 'INSCRIT'
15
+ @registration_date = @raw.dig('registrationDate')
16
+ @collect_funds = @raw.dig('collectFunds') == 'true'
17
+
18
+ raw_mandators = @raw.dig('mandators', 'mandator')
19
+ unless raw_mandators.is_a?(Array)
20
+ raw_mandators = [raw_mandators]
21
+ end
22
+
23
+ @mandators = raw_mandators.compact.map do |h|
24
+ Orias::Mandator.new(h)
25
+ end
26
+ end
27
+
28
+ private
29
+
30
+ class << self
31
+ end
32
+ end
33
+ end
@@ -0,0 +1,42 @@
1
+ require 'net/http'
2
+
3
+ module Orias
4
+ # Dedicated to request handling to ORIAS API
5
+ #
6
+ class Request < Base
7
+ attr_reader :http, :post, :uri
8
+ attr_accessor :api_endpoint, :body
9
+
10
+ # Initialize an Orias::Request instance
11
+ def initialize(attributes = {})
12
+ super
13
+ @api_endpoint ||= Orias.configuration.api_endpoint
14
+ end
15
+
16
+ # Build the request to be sent
17
+ def build!
18
+ @uri = URI(@api_endpoint)
19
+
20
+ @post = Net::HTTP::Post.new(uri)
21
+ @post.body = @body
22
+ @post['Content-Type'] = 'application/xml'
23
+
24
+ @http = Net::HTTP.new(uri.host, uri.port)
25
+ @http.use_ssl = true
26
+
27
+ self
28
+ end
29
+
30
+ # Send the built request
31
+ def send!
32
+ build! unless @post && @http
33
+ @response = @http.request(@post)
34
+ @response
35
+ end
36
+
37
+ # Return or set #response if not already set
38
+ def response
39
+ @response || send!
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,82 @@
1
+ require 'libxml_to_hash'
2
+
3
+ module Orias
4
+ # Dedicated to search response handling
5
+ #
6
+ class Response < Base
7
+ VALID_TYPES = [:intermediary_search].freeze
8
+
9
+ attr_accessor :type, :raw_response, :raw_hash_response, :results
10
+
11
+ # Initialize an Orias::Response instance
12
+ def initialize(attributes = {})
13
+ super
14
+ self.process_raw_response!
15
+ end
16
+
17
+ # Result collections
18
+
19
+ [:found, :subscribed].each do |result_attr|
20
+
21
+ define_method("#{result_attr}") do |attr_value = true|
22
+ if @type == :intermediary_search
23
+ return send("#{result_attr}_intermediaries".to_sym, attr_value)
24
+ end
25
+
26
+ []
27
+ end
28
+
29
+ define_method("not_#{result_attr}") do
30
+ return send("#{result_attr}".to_sym, false)
31
+ end
32
+
33
+ define_method("#{result_attr}_intermediaries") do |attr_value = true|
34
+ return send(:results).select do |result|
35
+ result.send(result_attr) == attr_value
36
+ end
37
+ end
38
+
39
+ end
40
+
41
+ # Result collections methods
42
+
43
+ [:found, :not_found].each do |collection|
44
+
45
+ [:siren, :orias].each do |intermediary_attr|
46
+
47
+ define_method("#{collection}_#{intermediary_attr}") do
48
+ return send(collection).map do |intermediary|
49
+ intermediary.send(intermediary_attr)
50
+ end
51
+ end
52
+
53
+ end
54
+
55
+ end
56
+
57
+ protected
58
+
59
+ def process_raw_response!
60
+ self.raw_hash_response = Hash.from_libxml(self.raw_response)['Envelope']['Body']
61
+
62
+ if @type == :intermediary_search
63
+ process_intermediary_search!
64
+ else
65
+ self
66
+ end
67
+ end
68
+
69
+ private
70
+
71
+ def process_intermediary_search!
72
+ results_hash = self.raw_hash_response['intermediarySearchResponse']
73
+ results_hash = results_hash['intermediaries']['intermediary']
74
+
75
+ @results = results_hash.map do |h|
76
+ Orias::Intermediary.new(h)
77
+ end
78
+
79
+ self
80
+ end
81
+ end
82
+ end
@@ -0,0 +1,101 @@
1
+ require 'libxml_to_hash'
2
+
3
+ module Orias
4
+ # Dedicated to search request building
5
+ #
6
+ class Search < Base
7
+ VALID_INTERMEDIARIES_TYPE = { siren: 9, registrationNumber: 8 }.freeze
8
+
9
+ attr_accessor :client
10
+
11
+ # Initialize an Orias::Search instance
12
+ def initialize(attributes = {})
13
+ super
14
+ @client ||= Orias::Client.new
15
+ end
16
+
17
+ # Alias for #find_by with an :orias type
18
+ def find_by_orias(*terms)
19
+ find_by(:orias, terms)
20
+ end
21
+
22
+ # Alias for #find_by with an :siren type
23
+ def find_by_siren(*terms)
24
+ find_by(:siren, terms)
25
+ end
26
+
27
+ # Request building for intermediarySearchRequest
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
+ )
38
+ end
39
+
40
+ # Build the raw request body of a search
41
+ def raw_body(content)
42
+ xmlns_url = 'http://schemas.xmlsoap.org/soap/envelope/'
43
+
44
+ output = "<soapenv:Envelope xmlns:soapenv=\"#{xmlns_url}\">"
45
+ output += "<soapenv:Body>#{content}</soapenv:Body>"
46
+ output + '</soapenv:Envelope>'
47
+ end
48
+
49
+ # Build the raw search request of a search
50
+ def raw_find(raw_intermeds)
51
+ content = '<intermediarySearchRequest xmlns="urn:gpsa:orias:ws.001">'
52
+ content += "<user xmlns=\"\">#{@client.private_key}</user>"
53
+ content += "<intermediaries xmlns=\"\">#{raw_intermeds}</intermediaries>"
54
+ content += '</intermediarySearchRequest>'
55
+
56
+ raw_body(content)
57
+ end
58
+
59
+ # Build the raw intermediaries list of a search
60
+ def raw_intermediaries(type, terms)
61
+ raise 'Orias::Search - You must at least submit one term.' if terms.empty?
62
+
63
+ type = Search.set_type(type, terms)
64
+ terms = Search.set_terms(type, terms)
65
+
66
+ terms.flatten.uniq.compact.map do |term|
67
+ "<intermediary><#{type}>#{term}</#{type}></intermediary>\n"
68
+ end.join
69
+ end
70
+
71
+ class << self
72
+ # Check & Set the type for an intermediaries list
73
+ def set_type(type, terms)
74
+ type = :registrationNumber if type == :orias
75
+
76
+ return type if VALID_INTERMEDIARIES_TYPE.key?(type)
77
+
78
+ lgts = terms.map(&:length).uniq
79
+
80
+ unless lgts.length == 1 && VALID_INTERMEDIARIES_TYPE.invert[lgts.first]
81
+ raise "Orias::Search - Unknown Type Error (\"#{type}\")."
82
+ end
83
+
84
+ VALID_INTERMEDIARIES_TYPE.invert[lgts.first]
85
+ end
86
+
87
+ # Check & Set an intermediaries list
88
+ def set_terms(type, terms)
89
+ terms.map!{ |t| t.gsub(/\D/,'') }
90
+ lgts = terms.map(&:length).uniq
91
+ valid_lgth = VALID_INTERMEDIARIES_TYPE[type]
92
+
93
+ unless lgts.length == 1 && lgts.first == valid_lgth
94
+ raise "Terms for \"#{type}\" must all have a length of #{valid_lgth}."
95
+ end
96
+
97
+ terms
98
+ end
99
+ end
100
+ end
101
+ end
data/lib/orias/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Orias
2
- VERSION = '0.1.0'.freeze
2
+ VERSION = '0.2.0'.freeze
3
3
  end
data/lib/orias.rb CHANGED
@@ -1,5 +1,28 @@
1
+ require 'orias/base'
1
2
  require 'orias/version'
3
+ require 'orias/configuration'
4
+ require 'orias/request'
5
+ require 'orias/client'
6
+ require 'orias/search'
7
+ require 'orias/response'
8
+ require 'orias/intermediary'
9
+ require 'orias/registration'
10
+ require 'orias/mandator'
2
11
 
12
+ # Top-level of the orias ruby gem.
13
+ #
3
14
  module Orias
4
- # Your code goes here...
15
+ class << self
16
+ attr_writer :configuration
17
+ end
18
+
19
+ # Orias::Configuration instance accessor
20
+ def self.configuration
21
+ @configuration ||= Configuration.new
22
+ end
23
+
24
+ # Orias::Configuration instance builder
25
+ def self.configure
26
+ yield(configuration)
27
+ end
5
28
  end
data/orias.gemspec CHANGED
@@ -1,5 +1,4 @@
1
-
2
- lib = File.expand_path('../lib', __FILE__)
1
+ lib = File.expand_path('lib', __dir__)
3
2
  $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
3
  require 'orias/version'
5
4
 
@@ -15,25 +14,22 @@ Gem::Specification.new do |spec|
15
14
  spec.homepage = 'https://github.com/01max/orias'
16
15
  spec.license = 'MIT'
17
16
 
18
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the 'allowed_push_host'
19
- # to allow pushing to a single host or delete this section to allow pushing to any host.
20
- if spec.respond_to?(:metadata)
21
- # spec.metadata['allowed_push_host'] = 'TODO: Set to 'http://mygemserver.com''
22
- else
23
- raise 'RubyGems 2.0 or newer is required to protect against ' \
24
- 'public gem pushes.'
25
- end
26
-
27
17
  # Specify which files should be added to the gem when it is released.
28
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
29
- spec.files = Dir.chdir(File.expand_path('..', __FILE__)) do
30
- `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
18
+ # The `git ls-files -z` loads the files in the RubyGem
19
+ # that have been added into git.
20
+ spec.files = Dir.chdir(File.expand_path(__dir__)) do
21
+ `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
31
24
  end
32
25
  spec.bindir = 'exe'
33
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
34
27
  spec.require_paths = ['lib']
35
28
 
29
+ spec.add_runtime_dependency('libxml-to-hash')
30
+
36
31
  spec.add_development_dependency('bundler', '~> 1.16')
32
+ spec.add_development_dependency('faker', '~> 1.9')
37
33
  spec.add_development_dependency('rake', '~> 10.0')
38
34
  spec.add_development_dependency('rspec', '~> 3.0')
39
35
  spec.add_development_dependency('rubocop')
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: orias
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.2.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-05 00:00:00.000000000 Z
11
+ date: 2019-01-24 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: libxml-to-hash
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: bundler
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -24,6 +38,20 @@ dependencies:
24
38
  - - "~>"
25
39
  - !ruby/object:Gem::Version
26
40
  version: '1.16'
41
+ - !ruby/object:Gem::Dependency
42
+ name: faker
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.9'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.9'
27
55
  - !ruby/object:Gem::Dependency
28
56
  name: rake
29
57
  requirement: !ruby/object:Gem::Requirement
@@ -103,6 +131,7 @@ extra_rdoc_files: []
103
131
  files:
104
132
  - ".gitignore"
105
133
  - ".rspec"
134
+ - ".rubocop.yml"
106
135
  - ".travis.yml"
107
136
  - Gemfile
108
137
  - Gemfile.lock
@@ -112,6 +141,15 @@ files:
112
141
  - bin/console
113
142
  - bin/setup
114
143
  - lib/orias.rb
144
+ - lib/orias/base.rb
145
+ - lib/orias/client.rb
146
+ - lib/orias/configuration.rb
147
+ - lib/orias/intermediary.rb
148
+ - lib/orias/mandator.rb
149
+ - lib/orias/registration.rb
150
+ - lib/orias/request.rb
151
+ - lib/orias/response.rb
152
+ - lib/orias/search.rb
115
153
  - lib/orias/version.rb
116
154
  - orias.gemspec
117
155
  homepage: https://github.com/01max/orias