Sha256: a362fbe588546cfce58e43dd1f8eba96d2b5ff02a13eb46841ff406756cc8b9c
Contents?: true
Size: 1.84 KB
Versions: 40
Compression:
Stored size: 1.84 KB
Contents
module Alula class ClientConfiguration attr_accessor :api_url, :debug, :user_agent REQUEST_ATTRIBUTES = %i[api_key customer_id] # Using RequestStore so we're thread safe even with our non-thread-safe architecture :( REQUEST_ATTRIBUTES.each do |prop| define_method(prop) do RequestStore.store["alula_#{prop}"] end define_method("#{prop}=") do |value| RequestStore.store["alula_#{prop}"] = value end end # Stash the user type as a role for us to infer from later # You can set a symbolized role via role = :user, or provide the string userType # We cast to a symbolized role for ease of use in consumers. def role=(user_type) unless user_type.is_a?(Symbol) || user_type.is_a?(String) raise Alula::InvalidRoleError, 'Role must be symbol or string' end RequestStore.store['alula_role'] = Util.underscore(user_type).to_sym end def role RequestStore.store['alula_role'] end def ensure_api_key_set if api_key.nil? raise Alula::NotConfiguredError, 'Set your API access token before making requests with Alula::Client.config.api_key = {access_token}' end end def ensure_api_url_set if api_url.nil? raise Alula::NotConfiguredError, 'did you forget to set the Alula::Client.config.api_url config option?' end end def ensure_customer_id_set unless customer_id raise Alula::NotConfiguredError, 'Set your customer_id before making requests to the video API' end end def ensure_role_set if role.nil? message = 'User role not configured! You must set '\ 'Alula::Client.config.role '\ 'before attempting to save any resources' raise Alula::NotConfiguredError, message end end end end
Version data entries
40 entries across 40 versions & 1 rubygems