Class: Restify::Request
- Inherits:
-
Object
- Object
- Restify::Request
- Defined in:
- lib/restify/request.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Request data.
-
#headers ⇒ Object
readonly
Request headers.
-
#method ⇒ String
readonly
HTTP method.
-
#timeout ⇒ Object
readonly
Request timeout in seconds.
-
#uri ⇒ String
readonly
Request URI.
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(uri:, method: :get, data: nil, timeout: 300, headers: {}) ⇒ Request
constructor
A new instance of Request.
- #to_s ⇒ Object
Constructor Details
#initialize(uri:, method: :get, data: nil, timeout: 300, headers: {}) ⇒ Request
Returns a new instance of Request.
32 33 34 35 36 37 38 39 40 |
# File 'lib/restify/request.rb', line 32 def initialize(uri:, method: :get, data: nil, timeout: 300, headers: {}) @uri = uri @method = method.to_s.downcase @data = data @timeout = timeout @headers = headers @headers['Content-Type'] ||= 'application/json' if json? end |
Instance Attribute Details
#data ⇒ Object (readonly)
Request data.
20 21 22 |
# File 'lib/restify/request.rb', line 20 def data @data end |
#headers ⇒ Object (readonly)
Request headers
24 25 26 |
# File 'lib/restify/request.rb', line 24 def headers @headers end |
#method ⇒ String (readonly)
HTTP method.
10 11 12 |
# File 'lib/restify/request.rb', line 10 def method @method end |
#timeout ⇒ Object (readonly)
Request timeout in seconds
Defaults to 300 seconds.
30 31 32 |
# File 'lib/restify/request.rb', line 30 def timeout @timeout end |
#uri ⇒ String (readonly)
Request URI.
16 17 18 |
# File 'lib/restify/request.rb', line 16 def uri @uri end |
Instance Method Details
#body ⇒ Object
42 43 44 |
# File 'lib/restify/request.rb', line 42 def body @body ||= json? ? JSON.dump(@data) : @data end |
#to_s ⇒ Object
46 47 48 |
# File 'lib/restify/request.rb', line 46 def to_s "#<#{self.class} #{method.upcase} #{uri}>" end |