Sha256: b16233bbb6fa505dc73d919eac4c59913d952a7df51cfc85644dfe33e85cf2a5

Contents?: true

Size: 1.41 KB

Versions: 5

Compression:

Stored size: 1.41 KB

Contents

require_relative '../soaspec'

# This represents a request / response pair
class Exchange

  attr_reader :api_class

  def initialize(name, override_parameters = {})
    @test_name = name.to_s
    @api_class = Soaspec::Environment.api_handler
    @override_parameters = override_parameters
  end

  # Make request to handler with parameters defined
  def make_request
    @api_class.make_request(@override_parameters)
  end

  # Name describing this class when used with `RSpec.describe`
  # This will make the request and store the response
  # @return [String] Name given when initializing
  def to_s
    Soaspec::SpecLogger.add_to 'Example ' + @test_name
    @test_name
  end

  # Returns response object from Api. Will make the request if not made and then cache it for later on
  # For example for SOAP it will be a Savon response
  # response.body (body of response as Hash)
  # response.header (head of response as Hash)
  def response
    @response ||= make_request
  end

  # Get status code from api class. This is http response for Web Api
  # @return [Integer] Status code from api class
  def status_code
    @api_class.status_code_for(self.response)
  end

  # Extract value from path api class
  # @param [Object] path Path to return element for api class E.g - for SOAP this is XPath string. For JSON, this is Hash dig Array
  # @return [String] Value at path
  def [](path)
    @api_class.value_from_path(self, path)
  end

end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
soaspec-0.0.35 lib/soaspec/exchange.rb
soaspec-0.0.34 lib/soaspec/exchange.rb
soaspec-0.0.33 lib/soaspec/exchange.rb
soaspec-0.0.32 lib/soaspec/exchange.rb
soaspec-0.0.31 lib/soaspec/exchange.rb