Class: Orias::Search
Overview
Dedicated to search request building
Constant Summary collapse
- VALID_INTERMEDIARIES_TYPE =
{ siren: 9, registrationNumber: 8 }.freeze
Instance Attribute Summary collapse
-
#client ⇒ Object
Returns the value of attribute client.
Class Method Summary collapse
-
.set_terms(type, terms) ⇒ Object
Check & Set an intermediaries list.
-
.set_type(type, terms) ⇒ Object
Check & Set the type for an intermediaries list.
Instance Method Summary collapse
-
#find_by(type, terms) ⇒ Object
Request building for intermediarySearchRequest.
-
#find_by_orias(*terms) ⇒ Object
Alias for #find_by with an :orias type.
-
#find_by_siren(*terms) ⇒ Object
Alias for #find_by with an :siren type.
-
#initialize(attributes = {}) ⇒ Search
constructor
Initialize an Orias::Search instance.
-
#raw_body(content) ⇒ Object
Build the raw request body of a search.
-
#raw_find(raw_intermeds) ⇒ Object
Build the raw search request of a search.
-
#raw_intermediaries(type, terms) ⇒ Object
Build the raw intermediaries list of a search.
Constructor Details
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
9 10 11 |
# File 'lib/orias/search.rb', line 9 def client @client end |
Class Method Details
.set_terms(type, terms) ⇒ Object
Check & Set an intermediaries list
88 89 90 91 92 93 94 95 96 97 98 |
# File 'lib/orias/search.rb', line 88 def set_terms(type, terms) terms.map!{ |t| t.gsub(/\D/,'') } lgts = terms.map(&:length).uniq valid_lgth = VALID_INTERMEDIARIES_TYPE[type] unless lgts.length == 1 && lgts.first == valid_lgth raise "Terms for \"#{type}\" must all have a length of #{valid_lgth}." end terms end |
.set_type(type, terms) ⇒ Object
Check & Set the type for an intermediaries list
73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/orias/search.rb', line 73 def set_type(type, terms) type = :registrationNumber if type == :orias return type if VALID_INTERMEDIARIES_TYPE.key?(type) lgts = terms.map(&:length).uniq unless lgts.length == 1 && VALID_INTERMEDIARIES_TYPE.invert[lgts.first] raise "Orias::Search - Unknown Type Error (\"#{type}\")." end VALID_INTERMEDIARIES_TYPE.invert[lgts.first] end |
Instance Method Details
#find_by(type, terms) ⇒ Object
Request building for intermediarySearchRequest
28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/orias/search.rb', line 28 def find_by(type, terms) request = Orias::Request.new( api_endpoint: @client.api_endpoint, body: raw_find(raw_intermediaries(type, terms)) ).build! Orias::Response.new( type: :intermediary_search, raw_response: request.response.body ) end |
#find_by_orias(*terms) ⇒ Object
Alias for #find_by with an :orias type
18 19 20 |
# File 'lib/orias/search.rb', line 18 def find_by_orias(*terms) find_by(:orias, terms) end |
#find_by_siren(*terms) ⇒ Object
Alias for #find_by with an :siren type
23 24 25 |
# File 'lib/orias/search.rb', line 23 def find_by_siren(*terms) find_by(:siren, terms) end |
#raw_body(content) ⇒ Object
Build the raw request body of a search
41 42 43 44 45 46 47 |
# File 'lib/orias/search.rb', line 41 def raw_body(content) xmlns_url = 'http://schemas.xmlsoap.org/soap/envelope/' output = "<soapenv:Envelope xmlns:soapenv=\"#{xmlns_url}\">" output += "<soapenv:Body>#{content}</soapenv:Body>" output + '</soapenv:Envelope>' end |
#raw_find(raw_intermeds) ⇒ Object
Build the raw search request of a search
50 51 52 53 54 55 56 57 |
# File 'lib/orias/search.rb', line 50 def raw_find(raw_intermeds) content = '<intermediarySearchRequest xmlns="urn:gpsa:orias:ws.001">' content += "<user xmlns=\"\">#{@client.private_key}</user>" content += "<intermediaries xmlns=\"\">#{raw_intermeds}</intermediaries>" content += '</intermediarySearchRequest>' raw_body(content) end |
#raw_intermediaries(type, terms) ⇒ Object
Build the raw intermediaries list of a search
60 61 62 63 64 65 66 67 68 69 |
# File 'lib/orias/search.rb', line 60 def raw_intermediaries(type, terms) raise 'Orias::Search - You must at least submit one term.' if terms.empty? type = Search.set_type(type, terms) terms = Search.set_terms(type, terms) terms.flatten.uniq.compact.map do |term| "<intermediary><#{type}>#{term}</#{type}></intermediary>\n" end.join end |