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.
-
#uri ⇒ String
readonly
Request URI.
Instance Method Summary collapse
- #body ⇒ Object
-
#initialize(opts = {}) ⇒ Request
constructor
A new instance of Request.
Constructor Details
#initialize(opts = {}) ⇒ Request
Returns a new instance of Request.
27 28 29 30 31 32 33 |
# File 'lib/restify/request.rb', line 27 def initialize(opts = {}) @method = opts.fetch(:method, :get).downcase @uri = opts.fetch(:uri) { raise ArgumentError.new ':uri required.' } @data = opts.fetch(:data, nil) @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 |
#uri ⇒ String (readonly)
Request URI.
17 18 19 |
# File 'lib/restify/request.rb', line 17 def uri @uri end |
Instance Method Details
#body ⇒ Object
35 36 37 38 39 |
# File 'lib/restify/request.rb', line 35 def body @body ||= begin JSON.dump(data) unless data.nil? end end |