Class: RoadForest::TestSupport::HTTPClient::Exchange

Inherits:
Object
  • Object
show all
Defined in:
lib/roadforest/test-support/http-client.rb

Defined Under Namespace

Classes: RequestBody

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeExchange

Returns a new instance of Exchange.



63
64
65
66
67
68
69
70
# File 'lib/roadforest/test-support/http-client.rb', line 63

def initialize
  @uri = nil
  @method = nil
  @headers = Webmachine::Headers.new
  @query_params = {}
  @req = nil
  @res = nil
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



71
72
73
# File 'lib/roadforest/test-support/http-client.rb', line 71

def body
  @body
end

#dispatcherObject

Returns the value of attribute dispatcher.



71
72
73
# File 'lib/roadforest/test-support/http-client.rb', line 71

def dispatcher
  @dispatcher
end

#headersObject

Returns the value of attribute headers.



72
73
74
# File 'lib/roadforest/test-support/http-client.rb', line 72

def headers
  @headers
end

#methodObject

Returns the value of attribute method.



71
72
73
# File 'lib/roadforest/test-support/http-client.rb', line 71

def method
  @method
end

#query_paramsObject

Returns the value of attribute query_params.



72
73
74
# File 'lib/roadforest/test-support/http-client.rb', line 72

def query_params
  @query_params
end

#uriObject

Returns the value of attribute uri.



71
72
73
# File 'lib/roadforest/test-support/http-client.rb', line 71

def uri
  @uri
end

Instance Method Details

#do_requestObject



105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/roadforest/test-support/http-client.rb', line 105

def do_request
  self.uri = Addressable::URI.parse(uri)
  uri.query_values = (uri.query_values || {}).merge(query_params)


  @req = Webmachine::Request.new(method, uri, headers, RequestBody.new(body))
  @res = Webmachine::Response.new

  dispatcher.dispatch(@req, @res)

  return @res
end

#header(name, value) ⇒ Object

Set a single header for the next request.



85
86
87
# File 'lib/roadforest/test-support/http-client.rb', line 85

def header(name, value)
  @headers[name] = value
end

#query_param(name, value) ⇒ Object



95
96
97
# File 'lib/roadforest/test-support/http-client.rb', line 95

def query_param(name, value)
  @query_params[name] = value
end

#requestObject

Returns the request object.



75
76
77
# File 'lib/roadforest/test-support/http-client.rb', line 75

def request
  @req || webmachine_test_error('No request object yet. Issue a request first.')
end

#responseObject

Returns the response object after a request has been made.



80
81
82
# File 'lib/roadforest/test-support/http-client.rb', line 80

def response
  @res || webmachine_test_error('No response yet. Issue a request first!')
end