lib/global_session/session.rb in global_session-2.0.3 vs lib/global_session/session.rb in global_session-3.0.0
- old
+ new
@@ -4,10 +4,11 @@
end
require 'global_session/session/abstract'
require 'global_session/session/v1'
require 'global_session/session/v2'
+require 'global_session/session/v3'
# Ladies and gentlemen: the one and only, star of the show, GLOBAL SESSION!
#
# Session is designed to act as much like a Hash as possible. You can use
# most of the methods you would use with Hash: [], has_key?, each, etc. It has a
@@ -22,17 +23,29 @@
#
# This module also acts as a façade for reading global session cookies generated
# by the different versions; it is responsible for detecting the version of
# a given cookie, then instantiating a suitable session object.
module GlobalSession::Session
- def self.decode_cookie(*args)
- V2.decode_cookie(*args)
- rescue GlobalSession::MalformedCookie => e
- V1.decode_cookie(*args)
+ # Decode a global session cookie without
+ def self.decode_cookie(cookie)
+ guess_version(cookie).decode_cookie(cookie)
end
def self.new(directory, cookie=nil, valid_signature_digest=nil)
- V2.new(directory, cookie)
- rescue GlobalSession::MalformedCookie => e
- V1.new(directory, cookie, valid_signature_digest)
+ guess_version(cookie).new(directory, cookie)
+ end
+
+ private
+
+ def self.guess_version(cookie)
+ case cookie
+ when /^WzM/
+ V3
+ when /^l9o/
+ V2
+ when /^eNo/
+ V1
+ else
+ V3
+ end
end
end