Class: LedSign::Session

Inherits:
Object
  • Object
show all
Defined in:
lib/ledsign-api.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(token = nil, params = nil) ⇒ Session

Returns a new instance of Session.



33
34
35
36
37
38
39
40
41
# File 'lib/ledsign-api.rb', line 33

def initialize(token = nil, params = nil)
  self.token = token

  if params && params[:signature]
    unless self.class.validate_signature(params) && params[:timestamp].to_i > 24.hours.ago.utc.to_i
      raise "Invalid Signature: Possible malicious login" 
    end
  end
end

Instance Attribute Details

#nameObject

Returns the value of attribute name.



27
28
29
# File 'lib/ledsign-api.rb', line 27

def name
  @name
end

#tokenObject

Returns the value of attribute token.



27
28
29
# File 'lib/ledsign-api.rb', line 27

def token
  @token
end

Class Method Details

.setup(params) ⇒ Object



29
30
31
# File 'lib/ledsign-api.rb', line 29

def self.setup(params)
  params.each { |k,value| send("#{k}=", value) }
end

Instance Method Details

#login_urlObject



43
44
45
# File 'lib/ledsign-api.rb', line 43

def 
  "http://#{self.class.url}/login/?api_key=#{api_key}"
end

#siteObject

Used by ActiveResource::Base to make all non-authentication API calls (ShopifyAPI::Base.site set in ShopifyLoginProtection#shopify_session)



49
50
51
# File 'lib/ledsign-api.rb', line 49

def site
  "#{protocol}://#{api_key}:#{computed_password}@#{self.class.url}"
end

#valid?Boolean

Returns:

  • (Boolean)


53
54
55
# File 'lib/ledsign-api.rb', line 53

def valid?
  token.present?
end