Module: Restspec::Endpoints::Network

Extended by:
Network
Included in:
Network
Defined in:
lib/restspec/endpoints/network.rb

Defined Under Namespace

Classes: HTTPartyNetworkAdapter

Instance Method Summary collapse

Instance Method Details

#request(request_object) ⇒ Restspec::Endpoints::Response

Make a request using a request object to some place. To actually send the information through the wire, this method uses a network adapter, that defaults to an instance of HTTPartyNetworkAdapter, that uses the httparty gem to make the request.

The network adapter can be replaced setting the following option in the Restspec configuration:

config.request.network_adapter = ->{ MyAwesomeNetworkAdapter.new }

This new MyAwesomeNetworkAdapter class should respond to just one method called request that returns a triad of values: A status code, the response headers and the body of the response. For example:

class MyAwesomeNetworkAdapter
  def request(request_object) # it just echoes the payload
    [200, {'Content-Type' => 'application/json'}, request_object.payload || {}]
  end
end

Parameters:

Returns:



30
31
32
33
# File 'lib/restspec/endpoints/network.rb', line 30

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