Class: Restfully::HTTP::Request
- Defined in:
- lib/restfully/http/request.rb
Constant Summary
Constants included from Parsing
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#retries ⇒ Object
Returns the value of attribute retries.
-
#uri ⇒ Object
readonly
Returns the value of attribute uri.
Instance Method Summary collapse
- #add_headers(headers = {}) ⇒ Object
- #body ⇒ Object
-
#initialize(url, options = {}) ⇒ Request
constructor
A new instance of Request.
- #raw_body ⇒ Object
Methods included from Headers
Methods included from Parsing
#select_parser_for, #serialize, #unserialize
Constructor Details
#initialize(url, options = {}) ⇒ Request
Returns a new instance of Request.
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/restfully/http/request.rb', line 10 def initialize(url, = {}) = .symbolize_keys @uri = url.kind_of?(URI) ? url : URI.parse(url) @headers = sanitize_http_headers(.delete(:headers) || {}) if query = .delete(:query) @uri.query = [@uri.query, query.to_params].compact.join("&") end @body = .delete(:body) @retries = 0 end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
7 8 9 |
# File 'lib/restfully/http/request.rb', line 7 def headers @headers end |
#retries ⇒ Object
Returns the value of attribute retries.
8 9 10 |
# File 'lib/restfully/http/request.rb', line 8 def retries @retries end |
#uri ⇒ Object (readonly)
Returns the value of attribute uri.
7 8 9 |
# File 'lib/restfully/http/request.rb', line 7 def uri @uri end |
Instance Method Details
#add_headers(headers = {}) ⇒ Object
37 38 39 |
# File 'lib/restfully/http/request.rb', line 37 def add_headers(headers = {}) @headers.merge!(sanitize_http_headers(headers || {})) end |
#body ⇒ Object
21 22 23 24 25 26 27 |
# File 'lib/restfully/http/request.rb', line 21 def body if @body.kind_of?(String) @unserialized_body ||= unserialize(@body, :content_type => @headers['Content-Type']) else @body end end |
#raw_body ⇒ Object
29 30 31 32 33 34 35 |
# File 'lib/restfully/http/request.rb', line 29 def raw_body if @body.kind_of?(String) @body else @serialized_body ||= serialize(@body, :content_type => @headers['Content-Type']) end end |