module Workarea::Orderbot::Authentication
Public Instance Methods
token()
click to toggle source
# File lib/workarea/orderbot/authentication.rb, line 4 def token response = get_token body = JSON.parse(response.body) body['token'] end
Private Instance Methods
api_password()
click to toggle source
# File lib/workarea/orderbot/authentication.rb, line 28 def api_password options[:api_password] end
api_user_name()
click to toggle source
# File lib/workarea/orderbot/authentication.rb, line 24 def api_user_name options[:api_user_name] end
get_token()
click to toggle source
# File lib/workarea/orderbot/authentication.rb, line 13 def get_token Rails.cache.fetch(token_cache_key, expires_in: 5.minutes) do conn = Faraday.new(url: rest_endpoint) conn.basic_auth(api_user_name, api_password) conn.get do |req| req.url '/accesstoken' req.headers['Content-Type'] = 'application/json' end end end
test()
click to toggle source
# File lib/workarea/orderbot/authentication.rb, line 32 def test options[:test] end
token_cache_key()
click to toggle source
# File lib/workarea/orderbot/authentication.rb, line 36 def token_cache_key Digest::MD5.hexdigest "#{api_user_name}#{api_password}#{test}" end