class Yardi::Utils::RequestFetcher

Send a SOAP request to Yardi

Attributes

connection[R]
endpoint[R]
generator[R]

Public Class Methods

new(connection:, endpoint:, generator:) click to toggle source

@param generator [RequestGenerator] an instance of a RequestGenerator,

which responds to #generate.

@param connection [Faraday::Connection] The connection we'll use to

make the request
# File lib/yardi/utils/request_fetcher.rb, line 14
def initialize(connection:, endpoint:, generator:)
  @connection = connection
  @endpoint = endpoint
  @generator = generator
end

Public Instance Methods

fetch() click to toggle source

@return [String] the XML response from Yardi

# File lib/yardi/utils/request_fetcher.rb, line 21
def fetch
  ConfigurationValidator.new.validate!

  response = perform!

  if response.status == 404
    raise Yardi::Error::ResourceNotFound, response.body
  end

  response.body
end

Private Instance Methods

perform!() click to toggle source
# File lib/yardi/utils/request_fetcher.rb, line 37
def perform!
  connection.post(endpoint) do |request|
    request.body = generator.body
    request.headers = generator.headers
  end
rescue Errno::EADDRNOTAVAIL => error
  raise Yardi::Error::ConnectionError, error.message
end