Class: Celluloid::Http::Request
- Inherits:
-
Object
- Object
- Celluloid::Http::Request
- Extended by:
- Forwardable
- Defined in:
- lib/celluloid-http/request.rb
Constant Summary collapse
- DEFAULT_METHOD =
:get- DEFAULT_HTTP_VERSION =
'1.1'
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#form_data ⇒ Object
Returns the value of attribute form_data.
-
#method ⇒ Object
Returns the value of attribute method.
Instance Method Summary collapse
-
#initialize(url, options = {}) ⇒ Request
constructor
A new instance of Request.
- #merge_query_params(params) ⇒ Object
- #query=(val) ⇒ Object
- #query_params ⇒ Object
- #to_s ⇒ Object
- #uri ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(url, options = {}) ⇒ Request
Returns a new instance of Request.
13 14 15 16 17 18 19 20 |
# File 'lib/celluloid-http/request.rb', line 13 def initialize(url, = {}) @uri = URI.parse url @method = [:method] || DEFAULT_METHOD @raw_body = [:raw_body] @form_data = [:form_data] merge_query_params([:query_params]) if [:query_params] end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
8 9 10 |
# File 'lib/celluloid-http/request.rb', line 8 def body @body end |
#form_data ⇒ Object
Returns the value of attribute form_data.
8 9 10 |
# File 'lib/celluloid-http/request.rb', line 8 def form_data @form_data end |
#method ⇒ Object
Returns the value of attribute method.
8 9 10 |
# File 'lib/celluloid-http/request.rb', line 8 def method @method end |
Instance Method Details
#merge_query_params(params) ⇒ Object
42 43 44 45 |
# File 'lib/celluloid-http/request.rb', line 42 def merge_query_params(params) params = query_params.merge params self.query = params end |
#query=(val) ⇒ Object
38 39 40 |
# File 'lib/celluloid-http/request.rb', line 38 def query=(val) @uri.query = val.is_a?(Hash) ? val.to_query : val end |
#query_params ⇒ Object
22 23 24 |
# File 'lib/celluloid-http/request.rb', line 22 def query_params Rack::Utils.parse_nested_query @uri.query end |
#to_s ⇒ Object
26 27 28 |
# File 'lib/celluloid-http/request.rb', line 26 def to_s "#{method.to_s.upcase} #{uri} HTTP/#{DEFAULT_HTTP_VERSION}\nHost: #{host}\n\n#{body}" end |
#uri ⇒ Object
34 35 36 |
# File 'lib/celluloid-http/request.rb', line 34 def uri "#{ "/" if path.length.zero? }#{path}#{ "?" if query }#{query}" end |
#url ⇒ Object
30 31 32 |
# File 'lib/celluloid-http/request.rb', line 30 def url @uri.to_s end |