lib/insales_api/app.rb in insales_api-0.0.1 vs lib/insales_api/app.rb in insales_api-0.0.2
- old
+ new
@@ -1,10 +1,10 @@
require 'digest/md5'
module InsalesApi
class App
cattr_accessor :api_key, :api_host, :api_secret, :api_autologin_path
- attr_accessor :shop, :password, :authorized, :auth_token
+ attr_reader :authorized, :auth_token, :shop, :password
def initialize(shop, password)
@authorized = false
@shop = self.class.prepare_shop shop
@password = password
@@ -14,19 +14,19 @@
store_auth_token
"http://#{shop}/admin/applications/#{self.class.api_key}/login?token=#{salt}&login=http://#{self.class.api_host}/#{self.class.api_autologin_path}"
end
def store_auth_token
- @auth_token = InsalesApi::Password.create(password, salt)
+ @auth_token ||= InsalesApi::Password.create(password, salt)
end
def salt
@salt ||= Digest::MD5.hexdigest("Twulvyeik#{$$}#{Time.now.to_i}thithAwn")
end
def authorize token
@authorized = false
- if self.auth_token == token
+ if self.auth_token and self.auth_token == token
@authorized = true
end
@authorized
end