Class: Wrest::Http::Request
- Inherits:
-
Object
- Object
- Wrest::Http::Request
- Defined in:
- lib/wrest/http/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#http_request ⇒ Object
readonly
Returns the value of attribute http_request.
-
#password ⇒ Object
readonly
Returns the value of attribute password.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
-
#username ⇒ Object
readonly
Returns the value of attribute username.
Instance Method Summary collapse
-
#initialize(wrest_uri, http_request_klass, parameters = {}, body = nil, headers = {}, options = {}) ⇒ Request
constructor
A new instance of Request.
-
#invoke ⇒ Object
Makes a request and returns a Wrest::Http::Response.
Constructor Details
#initialize(wrest_uri, http_request_klass, parameters = {}, body = nil, headers = {}, options = {}) ⇒ Request
Returns a new instance of Request.
13 14 15 16 17 18 19 20 21 |
# File 'lib/wrest/http/request.rb', line 13 def initialize(wrest_uri, http_request_klass, parameters = {}, body = nil, headers = {}, = {}) @uri = wrest_uri @headers = headers.stringify_keys @http_request = http_request_klass.new(parameters.empty? ? wrest_uri.full_path : "#{wrest_uri.full_path}?#{parameters.to_query}", @headers) @body = body = @username = [:username] @password = [:password] end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
12 13 14 |
# File 'lib/wrest/http/request.rb', line 12 def body @body end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
12 13 14 |
# File 'lib/wrest/http/request.rb', line 12 def headers @headers end |
#http_request ⇒ Object (readonly)
Returns the value of attribute http_request.
12 13 14 |
# File 'lib/wrest/http/request.rb', line 12 def http_request @http_request end |
#password ⇒ Object (readonly)
Returns the value of attribute password.
12 13 14 |
# File 'lib/wrest/http/request.rb', line 12 def password @password end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
12 13 14 |
# File 'lib/wrest/http/request.rb', line 12 def uri @uri end |
#username ⇒ Object (readonly)
Returns the value of attribute username.
12 13 14 |
# File 'lib/wrest/http/request.rb', line 12 def username @username end |
Instance Method Details
#invoke ⇒ Object
Makes a request and returns a Wrest::Http::Response. Data about the request is and logged to Wrest.logger
25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/wrest/http/request.rb', line 25 def invoke response = nil prefix = "#{http_request.method} #{http_request.hash}" http_request.basic_auth username, password Wrest.logger.debug "--> (#{prefix}) #{@uri.protocol}://#{@uri.host}:#{@uri.port}#{@http_request.path}" time = Benchmark.realtime { response = Wrest::Http::Response.new( http.request(@http_request, @body) ) } Wrest.logger.debug "<-- (#{prefix}) %d %s (%d bytes %.2fs)" % [response.code, response., response.body ? response.body.length : 0, time] response end |