Class: RoadForest::TestSupport::HTTPClient::Exchange
- Inherits:
-
Object
- Object
- RoadForest::TestSupport::HTTPClient::Exchange
- Defined in:
- lib/roadforest/test-support/http-client.rb
Defined Under Namespace
Classes: RequestBody
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#dispatcher ⇒ Object
Returns the value of attribute dispatcher.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
Returns the value of attribute method.
-
#query_params ⇒ Object
Returns the value of attribute query_params.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #do_request ⇒ Object
-
#header(name, value) ⇒ Object
Set a single header for the next request.
-
#initialize ⇒ Exchange
constructor
A new instance of Exchange.
- #query_param(name, value) ⇒ Object
-
#request ⇒ Object
Returns the request object.
-
#response ⇒ Object
Returns the response object after a request has been made.
Constructor Details
#initialize ⇒ Exchange
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
#body ⇒ Object
Returns the value of attribute body.
71 72 73 |
# File 'lib/roadforest/test-support/http-client.rb', line 71 def body @body end |
#dispatcher ⇒ Object
Returns the value of attribute dispatcher.
71 72 73 |
# File 'lib/roadforest/test-support/http-client.rb', line 71 def dispatcher @dispatcher end |
#headers ⇒ Object
Returns the value of attribute headers.
72 73 74 |
# File 'lib/roadforest/test-support/http-client.rb', line 72 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
71 72 73 |
# File 'lib/roadforest/test-support/http-client.rb', line 71 def method @method end |
#query_params ⇒ Object
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 |
#uri ⇒ Object
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_request ⇒ Object
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 |
#request ⇒ Object
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 |
#response ⇒ Object
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 |