module PrxAuth::Rails::AccountInfo
Constants
- PRX_ACCOUNT_MAPPING_SESSION_KEY
Public Instance Methods
Source
# File lib/prx_auth/rails/ext/controller/account_info.rb, line 12 def account_for(account_id) lookup_accounts([account_id]).first end
Source
# File lib/prx_auth/rails/ext/controller/account_info.rb, line 8 def account_name_for(account_id) account_for(account_id).try(:[], "name") end
Source
# File lib/prx_auth/rails/ext/controller/account_info.rb, line 16 def accounts_for(account_ids) lookup_accounts(account_ids) end
Private Instance Methods
Source
# File lib/prx_auth/rails/ext/controller/account_info.rb, line 39 def fetch_accounts(ids) ids_param = ids.map(&:to_s).join(",") path = "/api/v1/accounts?account_ids=#{ids_param}" url = "https://#{PrxAuth::Rails.configuration.id_host}#{path}" options = {} options[:ssl_verify_mode] = OpenSSL::SSL::VERIFY_NONE if ::Rails.env.development? resp = JSON.parse(URI.open(url, options).read) # standard:disable Security/Open resp.try(:[], "_embedded").try(:[], "prx:items") || [] end
Source
# File lib/prx_auth/rails/ext/controller/account_info.rb, line 22 def lookup_accounts(ids) return fetch_accounts(ids) unless defined?(session) session[PRX_ACCOUNT_MAPPING_SESSION_KEY] ||= {} # fetch any accounts we don't have yet missing = ids - session[PRX_ACCOUNT_MAPPING_SESSION_KEY].keys if missing.present? fetch_accounts(missing).each do |account| minimal = account.slice("name", "type") session[PRX_ACCOUNT_MAPPING_SESSION_KEY][account["id"]] = minimal end end ids.map { |id| session[PRX_ACCOUNT_MAPPING_SESSION_KEY][id] } end