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.
25 26 27 28 29 30 31 |
# File 'lib/restify/request.rb', line 25 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.
19 20 21 |
# File 'lib/restify/request.rb', line 19 def data @data end |
#headers ⇒ Object (readonly)
Request headers
23 24 25 |
# File 'lib/restify/request.rb', line 23 def headers @headers end |
#method ⇒ String (readonly)
HTTP method.
9 10 11 |
# File 'lib/restify/request.rb', line 9 def method @method end |
#uri ⇒ String (readonly)
Request URI.
15 16 17 |
# File 'lib/restify/request.rb', line 15 def uri @uri end |
Instance Method Details
#body ⇒ Object
33 34 35 36 37 |
# File 'lib/restify/request.rb', line 33 def body @body ||= begin JSON.dump(data) unless data.nil? end end |