Class: Spec::Client::Http::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/spec/client/http/session.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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, options = {})
  @client = client
  @cookie_jar = Mechanize::CookieJar.new
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



11
12
13
# File 'lib/spec/client/http/session.rb', line 11

def client
  @client
end

Returns the value of attribute cookie_jar.



11
12
13
# File 'lib/spec/client/http/session.rb', line 11

def cookie_jar
  @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.cookies.each do |cookie|
    cookie_jar.add(URI::parse(transaction.request.url),cookie)
  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.cookies(URI::parse(url)) }
end