Class: Twinfield::Api::Finder

Inherits:
BaseApi
  • Object
show all
Defined in:
lib/twinfield/api/finder.rb

Class Method Summary collapse

Methods inherited from BaseApi

client, cluster, cluster_short_name, session, session=

Class Method Details

.actionsObject



9
10
11
# File 'lib/twinfield/api/finder.rb', line 9

def actions
  @actions ||= client.operations
end

.request(type, options = {}) ⇒ Object



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/twinfield/api/finder.rb', line 15

def request(type, options = {})
  Twinfield.configuration.logger&.debug("#{caller.find { |a| !a.match(/\/gems\/|\/ruby\/|<internal:/) }}")

  first_row = options.delete(:first_row) || 1
  pattern = options.delete(:pattern) || "*"
  max_rows = options.delete(:max_rows) || 100

  message = {
    "type" => type,
    "pattern" => pattern,
    "field" => "0",
    "firstRow" => first_row,
    "maxRows" => max_rows,
    "options" => {
      "ArrayOfString" => options.map { |k, v| {"string" => [k, v]} }
    }
  }

  xml = client.operation(:search).build(attributes: {xmlns: "http://www.twinfield.com/"}, soap_header: session.header, message: message).build_document

  client.call(:search, xml: strip_global_namespace_from_xml(xml))
end

.strip_global_namespace_from_xml(xml) ⇒ Object



38
39
40
41
# File 'lib/twinfield/api/finder.rb', line 38

def strip_global_namespace_from_xml xml
  # ugly enough xmlns is prefixed even though it suggests an element in the global document's namespace
  xml.gsub("<xmlns:", "<").gsub("</xmlns:", "</")
end

.wsdlObject



5
6
7
# File 'lib/twinfield/api/finder.rb', line 5

def wsdl
  Twinfield::WSDLS[cluster_short_name][:finder]
end