Module: HTTParty_with_cookies
- Defined in:
- lib/httparty_with_cookies.rb
Instance Attribute Summary collapse
-
#cookies ⇒ Object
readonly
include HTTParty.
Class Method Summary collapse
Instance Method Summary collapse
- #request_cookies ⇒ Object
-
#set_cookies ⇒ Object
ugly hack to get the correct cookie array from the headers.
Instance Attribute Details
#cookies ⇒ Object (readonly)
include HTTParty
5 6 7 |
# File 'lib/httparty_with_cookies.rb', line 5 def @cookies end |
Class Method Details
.included(base) ⇒ Object
7 8 9 10 |
# File 'lib/httparty_with_cookies.rb', line 7 def self.included(base) base.extend HTTParty base.send :include, HTTParty end |
Instance Method Details
#request_cookies ⇒ Object
31 32 33 34 35 |
# File 'lib/httparty_with_cookies.rb', line 31 def URI.unescape( @cookies.to_a.map do || .join('=') end.join(';') ) end |
#set_cookies ⇒ Object
ugly hack to get the correct cookie array from the headers
36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/httparty_with_cookies.rb', line 36 def #ugly hack to get the correct cookie array from the headers headers = nil #3 years later: uglier meta hack to allow fetching headers from 3xx responses begin headers = @last_response.headers.instance_variable_get(:@header) rescue NoMethodError headers = @last_response.instance_variable_get(:@header) end return unless headers and headers['set-cookie'] = headers['set-cookie'] return unless and !.empty? = [ ] if .is_a? String .each do || ( .split(';')[0] ) end end |