Class: Sovren::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/sovren/client.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ Client

Initialize the client class that will be used for all sovren requests.

Parameters:

  • options (Hash) (defaults to: {})

Options Hash (options):

  • String (Object)

    :endpoint The url that the web service is located at

  • String (Object)

    :username The HTTP Basic auth username for the webservice

  • String (Object)

    :password The HTTP Basic auth password for the webservice

  • Integer (Object)

    :timeout The timeout for the parser

  • Integer (Object)

    :hard_time_out_multiplier The hard timeout for the parser

  • Integer (Object)

    :parser_configuration_params The parser configuration params, used to tweak the output of the parser



15
16
17
18
19
20
21
22
# File 'lib/sovren/client.rb', line 15

def initialize(options={})
  @endpoint = options[:endpoint]
  @username = options[:username]
  @password = options[:password]
  @timeout = options[:timout] || 30000
  @hard_time_out_multiplier = options[:hard_time_out_multiplier] || 2     
  @parser_configuration_params = options[:parser_configuration_params] || "_100000_0_00000010_0000000110101100_1_0000000000000111111102000000000010000100000000000000"
end

Instance Attribute Details

#endpointObject (readonly)

Returns the value of attribute endpoint.



3
4
5
# File 'lib/sovren/client.rb', line 3

def endpoint
  @endpoint
end

#hard_time_out_multiplierObject (readonly)

Returns the value of attribute hard_time_out_multiplier.



3
4
5
# File 'lib/sovren/client.rb', line 3

def hard_time_out_multiplier
  @hard_time_out_multiplier
end

#parser_configuration_paramsObject (readonly)

Returns the value of attribute parser_configuration_params.



3
4
5
# File 'lib/sovren/client.rb', line 3

def parser_configuration_params
  @parser_configuration_params
end

#passwordObject (readonly)

Returns the value of attribute password.



3
4
5
# File 'lib/sovren/client.rb', line 3

def password
  @password
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



3
4
5
# File 'lib/sovren/client.rb', line 3

def timeout
  @timeout
end

#usernameObject (readonly)

Returns the value of attribute username.



3
4
5
# File 'lib/sovren/client.rb', line 3

def username
  @username
end

Instance Method Details

#connectionObject



24
25
26
# File 'lib/sovren/client.rb', line 24

def connection
  Savon.client(wsdl: endpoint, log: false)
end

#convert(file, format) ⇒ Object



42
43
44
45
46
47
48
49
50
# File 'lib/sovren/client.rb', line 42

def convert(file, format)
  result = connection.call(:do_conversion_simplified) do |c|
    c.message({
      "DocumentAsByteArray" => Base64.encode64(file),
      "OutputType" => format})
  end

  result.body[:do_conversion_simplified_response][:do_conversion_simplified_result].to_s
end

#parse(file) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/sovren/client.rb', line 28

def parse(file)
  result = connection.call(:parse) do |c|
    c.message({
      "DocumentAsByteArray" => Base64.encode64(file),
      "ParserConfigurationParams" => parser_configuration_params,
      "AlsoUseSovrenTaxonomy" => true,
      "EmbedConvertedTextInHrXml" => true,
      "HardTimeOutMultiplier" => hard_time_out_multiplier,
      "TimeOutInMs" => timeout})
  end

  Resume.parse(result.body[:parse_response][:parse_result])
end