Class: Ldbws::Request::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/ldbws/request/base.rb

Overview

Base request type used whem querying LDBWS: provides basic functionality that can be overridden on a per-subclass basis.

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Base

Creates a Request object given the specified arguments. This performs validation accordng to the request’s schema, and throws ParamValidationError on failure.

Parameters

args

a Hash cotaining the request’s parameters



29
30
31
32
33
34
# File 'lib/ldbws/request/base.rb', line 29

def initialize(args)
  params = self.class::SCHEMA.(args)
  raise ParamValidationError.new(params.errors) if params.errors.any?

  @params = params.to_h
end

Instance Method Details

#from_soap(xml) ⇒ Object

Parses the returned SOAP response and converts it into the corresponding response type, defined in ‘RESULT_TYPE`.

Parameters

xml

the XML node that should contain the response to this request.



49
50
51
52
53
54
55
56
# File 'lib/ldbws/request/base.rb', line 49

def from_soap(xml)
  result_node = xml.xpath(self.class::RESULT_XPATH).first
  unless result_node
    raise Ldbws::ResponseParsingError("Root node not found (#{self.class::RESULT_XPATH})")
  end

  self.class::RESULT_TYPE.from_xml(result_node)
end

#to_soap(xml) ⇒ Object

Builds a SOAP request corresponding to the current request.

Parameters

xml

the Nokogiri Builder object to append XML to.



40
41
42
# File 'lib/ldbws/request/base.rb', line 40

def to_soap(xml)
  Ldbws::Utils.deep_to_soap(xml, to_soap_params)
end