Class: HTTPI::Cookie

Inherits:
Object
  • Object
show all
Defined in:
lib/httpi/cookie.rb

Overview

HTTPI::Cookie

Represents a single delicious cookie.

Examples

cookie = HTTPI::Cookie.new("token=choc-choc-chip; Path=/; HttpOnly")

cookie.name            # "token"
cookie.name_and_value  # "token=choc-choc-chip"

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(cookie) ⇒ Cookie

Returns a new instance of Cookie.



20
21
22
# File 'lib/httpi/cookie.rb', line 20

def initialize(cookie)
  @cookie = cookie
end

Class Method Details

.list_from_headers(headers) ⇒ Object

Returns a list of cookies from a Hash of headers.



16
17
18
# File 'lib/httpi/cookie.rb', line 16

def self.list_from_headers(headers)
  Array(headers["Set-Cookie"]).map { |cookie| new(cookie) }
end

Instance Method Details

#nameObject

Returns the name of the cookie.



25
26
27
# File 'lib/httpi/cookie.rb', line 25

def name
  @cookie.split("=").first
end

#name_and_valueObject

Returns the name and value of the cookie.



30
31
32
# File 'lib/httpi/cookie.rb', line 30

def name_and_value
  @cookie.split(";").first
end