Class: Pincers::Http::Request
- Inherits:
-
Object
- Object
- Pincers::Http::Request
- Defined in:
- lib/pincers/http/request.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#method ⇒ Object
Returns the value of attribute method.
-
#uri ⇒ Object
Returns the value of attribute uri.
Instance Method Summary collapse
- #clone_for_redirect(_location, _repeat = true) ⇒ Object
-
#initialize(_method, _uri) ⇒ Request
constructor
A new instance of Request.
- #native_type ⇒ Object
- #set_form_data(_pairs, _encoding = nil) ⇒ Object
- #set_query(_pairs) ⇒ Object
- #url ⇒ Object
Constructor Details
#initialize(_method, _uri) ⇒ Request
Returns a new instance of Request.
6 7 8 9 10 11 |
# File 'lib/pincers/http/request.rb', line 6 def initialize(_method, _uri) @method = _method @uri = _uri @headers = {} @data = nil end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/pincers/http/request.rb', line 4 def data @data end |
#headers ⇒ Object
Returns the value of attribute headers.
4 5 6 |
# File 'lib/pincers/http/request.rb', line 4 def headers @headers end |
#method ⇒ Object
Returns the value of attribute method.
4 5 6 |
# File 'lib/pincers/http/request.rb', line 4 def method @method end |
#uri ⇒ Object
Returns the value of attribute uri.
4 5 6 |
# File 'lib/pincers/http/request.rb', line 4 def uri @uri end |
Instance Method Details
#clone_for_redirect(_location, _repeat = true) ⇒ Object
53 54 55 56 57 58 59 60 61 62 |
# File 'lib/pincers/http/request.rb', line 53 def clone_for_redirect(_location, _repeat = true) clone = self.class.new(_repeat ? method : :get, _location) if _repeat clone.headers = clone.headers.clone clone.data = data end clone end |
#native_type ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/pincers/http/request.rb', line 17 def native_type case @method when :get then Net::HTTP::Get when :post then Net::HTTP::Post when :put then Net::HTTP::Put when :delete then Net::HTTP::Delete else nil end end |
#set_form_data(_pairs, _encoding = nil) ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/pincers/http/request.rb', line 31 def set_form_data(_pairs, _encoding = nil) _pairs = Utils.hash_to_pairs(_pairs) if _pairs.is_a? Hash encoding = default_encoding_for(_pairs) encoding = _encoding if !_encoding.nil? && encoding == Utils::FORM_URLENCODED if method == :get raise EncodingNotSupported, encoding if encoding != Utils::FORM_URLENCODED set_query _pairs else headers['Content-Type'] = encoding self.data = case encoding when Utils::FORM_URLENCODED Utils.encode_urlencoded _pairs when Utils::FORM_MULTIPART Utils.encode_multipart _pairs else raise Pincers::MissingFeatureError.new "form encoding: #{_encoding}" end end end |
#set_query(_pairs) ⇒ Object
26 27 28 29 |
# File 'lib/pincers/http/request.rb', line 26 def set_query(_pairs) _pairs = Utils.hash_to_pairs(_pairs) if _pairs.is_a? Hash @uri.query = Utils.encode_urlencoded(_pairs) end |
#url ⇒ Object
13 14 15 |
# File 'lib/pincers/http/request.rb', line 13 def url @uri.to_s end |