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(opts = {}) ⇒ Request
constructor
A new instance of Request.
- #to_s ⇒ Object
Constructor Details
#initialize(opts = {}) ⇒ Request
Returns a new instance of Request.
33 34 35 36 37 38 39 40 |
# File 'lib/restify/request.rb', line 33 def initialize(opts = {}) @method = opts.fetch(:method, :get).downcase @uri = opts.fetch(:uri) { raise ArgumentError.new ':uri required.' } @data = opts.fetch(:data, nil) @timeout = opts.fetch(:timeout, 300) @headers = opts.fetch(:headers, {}).merge \ 'Content-Type' => 'application/json' end |
Instance Attribute Details
#data ⇒ Object (readonly)
Request data.
21 22 23 |
# File 'lib/restify/request.rb', line 21 def data @data end |
#headers ⇒ Object (readonly)
Request headers
25 26 27 |
# File 'lib/restify/request.rb', line 25 def headers @headers end |
#method ⇒ String (readonly)
HTTP method.
11 12 13 |
# File 'lib/restify/request.rb', line 11 def method @method end |
#timeout ⇒ Object (readonly)
Request timeout in seconds
Defaults to 300 seconds.
31 32 33 |
# File 'lib/restify/request.rb', line 31 def timeout @timeout end |
#uri ⇒ String (readonly)
Request URI.
17 18 19 |
# File 'lib/restify/request.rb', line 17 def uri @uri end |
Instance Method Details
#body ⇒ Object
42 43 44 45 46 |
# File 'lib/restify/request.rb', line 42 def body @body ||= begin JSON.dump(data) unless data.nil? end end |
#to_s ⇒ Object
48 49 50 |
# File 'lib/restify/request.rb', line 48 def to_s "#<#{self.class} #{method.upcase} #{uri}>" end |