Class: Spec::Client::Http::Session
- Inherits:
-
Object
- Object
- Spec::Client::Http::Session
- Defined in:
- lib/spec/client/http/session.rb
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#cookie_jar ⇒ Object
readonly
Returns the value of attribute cookie_jar.
Instance Method Summary collapse
- #execute(request) ⇒ Object
- #get(url, params = {}) ⇒ Object
-
#initialize(client, options = {}) ⇒ Session
constructor
A new instance of Session.
- #post(url, params = {}) ⇒ Object
- #request_headers(url) ⇒ Object
Constructor Details
#initialize(client, options = {}) ⇒ Session
Returns a new instance of Session.
13 14 15 16 |
# File 'lib/spec/client/http/session.rb', line 13 def initialize(client, = {}) @client = client @cookie_jar = Mechanize::CookieJar.new end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
11 12 13 |
# File 'lib/spec/client/http/session.rb', line 11 def client @client end |
#cookie_jar ⇒ Object (readonly)
Returns the value of attribute cookie_jar.
11 12 13 |
# File 'lib/spec/client/http/session.rb', line 11 def @cookie_jar end |
Instance Method Details
#execute(request) ⇒ Object
30 31 32 33 34 35 36 37 |
# File 'lib/spec/client/http/session.rb', line 30 def execute(request) transaction = Transaction.new(request) transaction.execute transaction.response..each do || .add(URI::parse(transaction.request.url),) end transaction end |
#get(url, params = {}) ⇒ Object
18 19 20 |
# File 'lib/spec/client/http/session.rb', line 18 def get(url, params = {}) execute(Request.new(url, "GET", params, request_headers(url))) end |
#post(url, params = {}) ⇒ Object
22 23 24 |
# File 'lib/spec/client/http/session.rb', line 22 def post(url, params = {}) execute(Request.new(url, "POST", params, request_headers(url))) end |
#request_headers(url) ⇒ Object
26 27 28 |
# File 'lib/spec/client/http/session.rb', line 26 def request_headers(url) { "Cookie" => @cookie_jar.(URI::parse(url)) } end |