Sha256: 3e36fa51494bf00aca7169b24592e1a19f228e4051a083ad1341db3a9b7df62b

Contents?: true

Size: 905 Bytes

Versions: 2

Compression:

Stored size: 905 Bytes

Contents

module Restspec
  module Endpoints
    module Network
      extend self

      def request(request_object)
        code, headers, body = network_adapter.request(request_object)
        Response.new(code, headers, body)
      end

      private

      def network_adapter
        network_adapter_lambda.try(:call) || default_network_adapter
      end

      def network_adapter_lambda
        Restspec.config.request.try(:network_adapter)
      end

      def default_network_adapter
        HTTPartyNetworkAdapter.new
      end

      class HTTPartyNetworkAdapter
        def request(request_object)
          response = HTTParty.send(
            request_object.method,
            request_object.url,
            headers: request_object.headers,
            body: request_object.raw_payload
          )

          [response.code, response.headers, response.body]
        end
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
restspec-0.0.4 lib/restspec/endpoints/network.rb
restspec-0.0.3 lib/restspec/endpoints/network.rb