lib/yardi/request/base.rb in yardi-4.0.8 vs lib/yardi/request/base.rb in yardi-4.11.0

- old
+ new

@@ -21,10 +21,11 @@ # 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. class Base attr_reader :connection, :credential, :response + # @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. @@ -43,15 +44,19 @@ parser.parse(@response) end # @return [String] the XMl response from Yardi def xml - Utils::RequestFetcher.new( - connection: connection, - endpoint: credential.web_service_url, - generator: generator - ).fetch + if request_test_data? + fetch_test_data + else + Utils::RequestFetcher.new( + connection: connection, + endpoint: credential.web_service_url, + generator: generator + ).fetch + end end # This makes it easy for us to see what XML we're about to send when # debugging requests def generator @@ -89,9 +94,26 @@ end # Each request must specify its associated interface. def interface raise NotImplementedError + end + + def request_test_data? + params[:test_data] == true + end + + def request_name + self.class.name.split('::').last + end + + def fetch_test_data + case request_name + when 'GetResidents' + Utils::TestDataFetcher.residents(params[:property_id]) + when 'GetYardiGuestActivity' + Utils::TestDataFetcher.guest_card_activity(params[:property_id], params[:prospect]) + end end end private_constant :Base end