Class: Akephalos::Client::Cookies

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/akephalos/client/cookies.rb

Overview

Interface for working with HtmlUnit’s CookieManager, providing a basic API for manipulating the cookies in a session.

Defined Under Namespace

Classes: Cookie

Instance Method Summary collapse

Constructor Details

#initialize(cookie_manager) ⇒ Cookies

Returns a new instance of Cookies.

Parameters:

  • cookie (HtmlUnit::CookieManager)

    manager



9
10
11
# File 'lib/akephalos/client/cookies.rb', line 9

def initialize(cookie_manager)
  @cookie_manager = cookie_manager
end

Instance Method Details

#[](name) ⇒ Cookie?

Parameters:

  • the (name)

    cookie name

Returns:

  • (Cookie)

    the cookie with the given name

  • (nil)

    when no cookie is found



16
17
18
19
# File 'lib/akephalos/client/cookies.rb', line 16

def [](name)
  cookie = @cookie_manager.getCookie(name)
  Cookie.new(cookie) if cookie
end

#clearObject

Clears all cookies for this session.



22
23
24
# File 'lib/akephalos/client/cookies.rb', line 22

def clear
  @cookie_manager.clearCookies
end

#delete(cookie) ⇒ Object

Remove the cookie from the session.

Parameters:

  • the (Cookie)

    cookie to remove



36
37
38
# File 'lib/akephalos/client/cookies.rb', line 36

def delete(cookie)
  @cookie_manager.removeCookie(cookie.native)
end

#eachObject

Iterator for all cookies in the current session.



27
28
29
30
31
# File 'lib/akephalos/client/cookies.rb', line 27

def each
  @cookie_manager.getCookies.each do |cookie|
    yield Cookie.new(cookie)
  end
end

#empty?true, false

Returns whether there are any cookies.

Returns:

  • (true, false)

    whether there are any cookies



41
42
43
# File 'lib/akephalos/client/cookies.rb', line 41

def empty?
  !any?
end