Class: Gemgento::Session

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/gemgento/session.rb

Overview

Author:

  • Gemgento LLC

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.get(client, force_new_session) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'app/models/gemgento/session.rb', line 6

def self.get(client, force_new_session)
  if Session.last.nil? || Session.last.expired || force_new_session
    response = client.call(:login, message: { username: Config[:magento][:username], apiKey: Config[:magento][:api_key] })

    unless response.success?
      puts 'Login Failed - Check Session'
      exit # cannot recover from this
    end

    session = response.body[:login_response][:login_return];

    s = Session.new
    s.session_id = session
    s.save
  else
    s = Session.last
    s.touch

    session = s.session_id
  end

  return session
end

Instance Method Details

#expiredObject



30
31
32
33
34
35
36
# File 'app/models/gemgento/session.rb', line 30

def expired
  if self.updated_at <= timeout.seconds.ago
    return true
  else
    return false
  end
end