Sha256: a0a3b70d72163ceb26984aec7cd09439f8e83ae11f5c418468ec5f39b8dd27a8
Contents?: true
Size: 1.07 KB
Versions: 2
Compression:
Stored size: 1.07 KB
Contents
module Garb class Session class << self; attr_reader :sessions end @sessions ||= [] def self.login(email, password, opts={}) auth_request = AuthenticationRequest.new(email, password) creds = { :email => email, :auth_token => auth_request.auth_token(opts) } update_or_create(creds) end def self.auth_token(email=nil) email ? find_session(email).auth_token : default.auth_token end def self.email(email=nil) email || default.email end def self.find_session(email) @sessions.find {|session| session.email == email} end def self.default @sessions.first end def self.update_or_create(creds) if session = find_session(creds[:email]) session.auth_token = creds[:auth_token] else @sessions << session = new(creds) end session end def initialize(creds={}) @email = creds[:email] @auth_token = creds[:auth_token] end attr_accessor :auth_token attr_reader :email def profiles Profile.all(@email) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
jonuts-garb-0.2.3 | lib/garb/session.rb |
jonuts-garb-0.2.4 | lib/garb/session.rb |