class RealPage::Request::Base

Base class for actions that fetch and parse specific RealPage 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 '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.

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

pmc_id[R]
site_id[R]

Public Class Methods

new(params) click to toggle source

@param params [Hash<Symbol, Object>] the parameters needed to build the

XML request.

@option params pmc_id [String] the unique identifier for the property

management company in RealPage (required)

@option params site_id [String] the unique identifier for the property

in RealPage (required)
# File lib/real_page/request/base.rb, line 32
def initialize(params)
  %i[pmc_id site_id].each do |required_param|
    unless params[required_param]
      raise ArgumentError, "Params must include :#{required_param}"
    end
  end
  @pmc_id = params[:pmc_id]
  @site_id = params[:site_id]
  after_initialize(params)
end

Public Instance Methods

perform() click to toggle source

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

from RealPage

@raise [RealPage::Error] an error when validating the response

# File lib/real_page/request/base.rb, line 46
def perform
  parser.parse(xml)
end
xml() click to toggle source

@return [String] the XMl response from RealPage

# File lib/real_page/request/base.rb, line 51
def xml
  generator =
    Utils::RequestGenerator.new(soap_action, [auth_section, *sections])
  Utils::RequestFetcher.new(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/real_page/request/base.rb, line 66
def after_initialize(params)
  # No-op, this method is a call back for subclasses
end
auth_section() click to toggle source
# File lib/real_page/request/base.rb, line 82
def auth_section
  RequestSection::Auth.new(pmc_id: pmc_id, site_id: site_id)
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/real_page/request/base.rb, line 73
def sections
  []
end
soap_action() click to toggle source

The CamelCased name of the SOAP action

# File lib/real_page/request/base.rb, line 78
def soap_action
  self.class.name.split('::').last
end