module Workarea::Sezzle::Authentication
Public Instance Methods
token()
click to toggle source
# File lib/workarea/sezzle/authentication.rb, line 5 def token response = get_token body = JSON.parse(response.body) raise AuthenticationError, response.body.to_s unless response.success? body['token'] end
Private Instance Methods
api_private_key()
click to toggle source
# File lib/workarea/sezzle/authentication.rb, line 36 def api_private_key options[:api_private_key] end
api_public_key()
click to toggle source
# File lib/workarea/sezzle/authentication.rb, line 32 def api_public_key options[:api_public_key] end
get_token()
click to toggle source
# File lib/workarea/sezzle/authentication.rb, line 15 def get_token Rails.cache.fetch(token_cache_key, expires_in: 5.minutes) do body = { public_key: api_public_key, private_key: api_private_key } conn = Faraday.new(url: rest_endpoint) conn.post do |req| req.url 'v2/authentication' req.headers['Content-Type'] = 'application/json' req.body = body.to_json end end end
test()
click to toggle source
# File lib/workarea/sezzle/authentication.rb, line 40 def test options[:test] end
token_cache_key()
click to toggle source
# File lib/workarea/sezzle/authentication.rb, line 44 def token_cache_key Digest::MD5.hexdigest "#{api_public_key}#{api_private_key}#{test}" end