class Yardi::Request::Base

Base class for actions that fetch and parse specific Yardi SOAP actions.

When subclassing this base class, you may override the following methods to extend functionality:

* after_initialize(params) - a hook into the initializer to give
  subclasses access to the parameters passed in. If the subclass uses
  any parameters that the base class is agnostic to, this is the place
  the set these values to instance variables
* sections (returns Array<RequestSection>) - add additional request
  sections to the request XML document. The necessary authentication
  data will always be inserted into the XML document by this class,
  so there is no need to add it to the response of this method.

Additionally, this base class provides the soap_action method, which returns the CamelCased name of the SOAP action being requested. This method assumes that the subclass will be named the same as the action.

Attributes

connection[R]
credential[R]
response[R]

Public Class Methods

new(credential:, params:) click to toggle source

@param credential [Parameter::Credential] contains the PMC-specific configuration information needed to make a request. We want to fail noisily if it's missing, so it is separate from the main params hash. @param params [Hash<Symbol, Object>] the parameters needed to build the

XML request.
# File lib/yardi/request/base.rb, line 31
def initialize(credential:, params:)
  @credential = credential
  @connection = params[:connection] || Faraday.new
  after_initialize(params)
end

Public Instance Methods

generator() click to toggle source

This makes it easy for us to see what XML we're about to send when debugging requests

# File lib/yardi/request/base.rb, line 57
def generator
  Utils::RequestGenerator.new(soap_action, sections, interface)
end
perform() click to toggle source

@return [Yardi::Model|Array<Yardi::Model>] the parsed response

from Yardi

@raise [Yardi::Error] if an error was encountered when validating

the response
# File lib/yardi/request/base.rb, line 41
def perform
  @response = xml
  parser.parse(@response)
end
xml() click to toggle source

@return [String] the XMl response from Yardi

# File lib/yardi/request/base.rb, line 47
def xml
  Utils::RequestFetcher.new(
    connection: connection,
    endpoint: credential.web_service_url,
    generator: generator
  ).fetch
end

Private Instance Methods

after_initialize(_params) click to toggle source

A hook into the initializer to give subclasses access to the parameters passed in. If the subclass uses any parameters that the base class is agnostic to, this is the place the set these values to instance variables

# File lib/yardi/request/base.rb, line 67
def after_initialize(_params)
  # No-op, this method is a call back for subclasses
end
interface() click to toggle source

Each request must specify its associated interface.

# File lib/yardi/request/base.rb, line 92
def interface
  raise NotImplementedError
end
sections() click to toggle source

A hook to add additional request sections to the request XML document. The 'auth' section will always be inserted into the XML document by this class, so there is no need to add it to the response of this method.

# File lib/yardi/request/base.rb, line 74
def sections
  { soap_body: soap_body_sections, xml_doc: xml_doc_sections }
end
soap_action() click to toggle source

Each request must specify its associated SOAP action.

# File lib/yardi/request/base.rb, line 87
def soap_action
  raise NotImplementedError
end
soap_body_sections() click to toggle source
# File lib/yardi/request/base.rb, line 78
def soap_body_sections
  []
end
xml_doc_sections() click to toggle source
# File lib/yardi/request/base.rb, line 82
def xml_doc_sections
  []
end