Class: BBC::Redux::Cookie
- Inherits:
-
Object
- Object
- BBC::Redux::Cookie
- Defined in:
- lib/bbc/redux/cookie.rb
Overview
Redux Cookie util class
A utility class for creating and parsing correct Redux cookies. Can be constructed from an existing client object or a raw cookie string
Instance Attribute Summary collapse
-
#client ⇒ BBC::Redux::Client
readonly
Client object built from token.
-
#string ⇒ String
(also: #to_s)
readonly
String representation of cookie, for use in HTTP responses Set-Cookie header.
-
#token ⇒ String
readonly
Session token.
Instance Method Summary collapse
-
#==(other_cookie) ⇒ Boolean
(also: #eql?)
True if other_cookie is a redux cookie with the same token.
-
#initialize(value) ⇒ Cookie
constructor
Build cookie from eith a client object or string value (the literal value of a prior HTTP cookie).
Constructor Details
#initialize(value) ⇒ Cookie
Build cookie from eith a client object or string value (the literal value of a prior HTTP cookie)
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/bbc/redux/cookie.rb', line 56 def initialize(value) if value.class == BBC::Redux::Client @token = value.token @client = value @string = build_string(token) elsif value.class == String if value =~ /BBC_video=(.*);\s+domain=.bbcredux.com;\s+path=\// @token = $1 @client = BBC::Redux::Client.new( :token => token ) @string = build_string(token) else raise ArgumentError.new('bad cookie format') end else raise ArgumentError.new('provide BBC::Redux::Client or String') end end |
Instance Attribute Details
#client ⇒ BBC::Redux::Client (readonly)
Returns client object built from token.
48 49 50 |
# File 'lib/bbc/redux/cookie.rb', line 48 def client @client end |
#string ⇒ String (readonly) Also known as: to_s
Returns string representation of cookie, for use in HTTP responses Set-Cookie header.
42 43 44 |
# File 'lib/bbc/redux/cookie.rb', line 42 def string @string end |
#token ⇒ String (readonly)
Returns session token.
37 38 39 |
# File 'lib/bbc/redux/cookie.rb', line 37 def token @token end |
Instance Method Details
#==(other_cookie) ⇒ Boolean Also known as: eql?
Returns true if other_cookie is a redux cookie with the same token.
76 77 78 |
# File 'lib/bbc/redux/cookie.rb', line 76 def ==() self.class == .class && self.token == .token end |