Class: CookieHash

Inherits:
Hash
  • Object
show all
Defined in:
lib/goshrine_bot/cookies.rb

Overview

Borrowed from HTTParty, a great rubygem from John Nunemaker (thanks!)

Constant Summary collapse

CLIENT_COOKIES =

:nodoc:

%w{path expires domain path secure HTTPOnly HttpOnly}

Instance Method Summary collapse

Methods inherited from Hash

from_array, #to_params

Instance Method Details

#add_cookies(value) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/goshrine_bot/cookies.rb', line 5

def add_cookies(value)
  return if value.nil?
  case value
  when Hash
    merge!(value)
  when String
    value.split('; ').each do |cookie|
      array = cookie.split('=')
      self[array[0].to_sym] = array[1]
    end
  else
    raise "add_cookies only takes a Hash or a String"
  end
end


20
21
22
# File 'lib/goshrine_bot/cookies.rb', line 20

def to_cookie_string
  delete_if { |k, v| CLIENT_COOKIES.include?(k.to_s) }.collect { |k, v| "#{k}=#{v}" }.join("; ")
end