Class: Session
- Inherits:
-
Object
- Object
- Session
- Defined in:
- lib/under_os/http/session.rb
Overview
Basically keeps track of cookies between the requests
Instance Method Summary collapse
- #cookies ⇒ Object
- #delete(url, options = {}, &block) ⇒ Object
- #get(url, options = {}, &block) ⇒ Object
-
#initialize(default_options = {}) ⇒ Session
constructor
A new instance of Session.
- #post(url, options = {}, &block) ⇒ Object
- #put(url, options = {}, &block) ⇒ Object
- #request(url, options = {}, &block) ⇒ Object
Constructor Details
#initialize(default_options = {}) ⇒ Session
Returns a new instance of Session.
5 6 7 8 |
# File 'lib/under_os/http/session.rb', line 5 def initialize(={}) @options = @options[:cookies] ||= {} end |
Instance Method Details
#cookies ⇒ Object
10 11 12 |
# File 'lib/under_os/http/session.rb', line 10 def @options[:cookies] end |
#delete(url, options = {}, &block) ⇒ Object
26 27 28 |
# File 'lib/under_os/http/session.rb', line 26 def delete(url, ={}, &block) request(url, {method: 'DELETE'}.merge(), &block).send end |
#get(url, options = {}, &block) ⇒ Object
14 15 16 |
# File 'lib/under_os/http/session.rb', line 14 def get(url, ={}, &block) request(url, {method: 'GET'}.merge(), &block).send end |
#post(url, options = {}, &block) ⇒ Object
18 19 20 |
# File 'lib/under_os/http/session.rb', line 18 def post(url, ={}, &block) request(url, {method: 'POST'}.merge(), &block).send end |
#put(url, options = {}, &block) ⇒ Object
22 23 24 |
# File 'lib/under_os/http/session.rb', line 22 def put(url, ={}, &block) request(url, {method: 'PUT'}.merge(), &block).send end |
#request(url, options = {}, &block) ⇒ Object
30 31 32 33 34 35 36 37 38 |
# File 'lib/under_os/http/session.rb', line 30 def request(url, ={}, &block) = .merge(@options){|k,a,b| a.merge(b) } UnderOs::HTTP::Request.new(url, , &block).tap do |request| request.on :response do |response| response.headers["Set-Cookie"] || '' end end end |