class HTTPI::Cookie

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"

Public Class Methods

list_from_headers(headers) click to toggle source

Returns a list of cookies from a Hash of headers.

# File lib/httpi/cookie.rb, line 16
def self.list_from_headers(headers)
  Array(headers["Set-Cookie"]).map { |cookie| new(cookie) }
end
new(cookie) click to toggle source
# File lib/httpi/cookie.rb, line 20
def initialize(cookie)
  @cookie = cookie
end

Public Instance Methods

name() click to toggle source

Returns the name of the cookie.

# File lib/httpi/cookie.rb, line 25
def name
  @cookie.split("=").first
end
name_and_value() click to toggle source

Returns the name and value of the cookie.

# File lib/httpi/cookie.rb, line 30
def name_and_value
  @cookie.split(";").first
end