class HTTPI::CookieStore

HTTPI::CookieStore

Stores a unique list of cookies for future requests.

Examples

# Add one or more cookies to the store
cookie_store = HTTPI::CookieStore.new
cookie_store.add HTTPI::Cookie.new("token=choc-choc-chip; Path=/; HttpOnly")

# Fetch the names and values for the "Cookie" header
cookie_store.fetch  # => "token=choc-choc-chip"

Public Class Methods

new() click to toggle source
# File lib/httpi/cookie_store.rb, line 17
def initialize
  @cookies = {}
end

Public Instance Methods

add(*cookies) click to toggle source

Adds one or more cookies to the store.

# File lib/httpi/cookie_store.rb, line 22
def add(*cookies)
  cookies.each do |cookie|
    @cookies[cookie.name] = cookie.name_and_value
  end
end
fetch() click to toggle source

Returns the names and values for the “Cookie” header.

# File lib/httpi/cookie_store.rb, line 29
def fetch
  @cookies.values.join(";") unless @cookies.empty?
end