module Restspec::Endpoints::Network
Public Instance Methods
Make a request using a {Restspec::Endpoints::Request 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](github.com/jnunemaker/httparty) gem to make the request.
The network adapter can be replaced setting the following option in the Restspec
configuration:
“`ruby 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:
“`ruby class MyAwesomeNetworkAdapter
def request(request_object) # it just echoes the payload [200, {'Content-Type' => 'application/json'}, request_object.payload || {}] end
end “`
@param request_object [Restspec::Endpoints::Request] the request to make. @return [Restspec::Endpoints::Response] the response from the wire.
# 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
Private Instance Methods
# File lib/restspec/endpoints/network.rb, line 45 def default_network_adapter HTTPartyNetworkAdapter.new end
# File lib/restspec/endpoints/network.rb, line 37 def network_adapter network_adapter_lambda.try(:call) || default_network_adapter end
# File lib/restspec/endpoints/network.rb, line 41 def network_adapter_lambda Restspec.config.request.try(:network_adapter) end