Class: Alula::ClientConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/alula/client_configuration.rb

Constant Summary collapse

REQUEST_ATTRIBUTES =
%i[api_key video_api_key customer_id internal impersonator_api_key]

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#api_urlObject

Returns the value of attribute api_url.



3
4
5
# File 'lib/alula/client_configuration.rb', line 3

def api_url
  @api_url
end

#debugObject

Returns the value of attribute debug.



3
4
5
# File 'lib/alula/client_configuration.rb', line 3

def debug
  @debug
end

#user_agentObject

Returns the value of attribute user_agent.



3
4
5
# File 'lib/alula/client_configuration.rb', line 3

def user_agent
  @user_agent
end

#video_api_urlObject

Returns the value of attribute video_api_url.



3
4
5
# File 'lib/alula/client_configuration.rb', line 3

def video_api_url
  @video_api_url
end

Instance Method Details

#ensure_api_key_setObject



33
34
35
36
37
38
# File 'lib/alula/client_configuration.rb', line 33

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

#ensure_api_url_setObject



40
41
42
43
44
# File 'lib/alula/client_configuration.rb', line 40

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

#ensure_customer_id_setObject



60
61
62
63
64
65
# File 'lib/alula/client_configuration.rb', line 60

def ensure_customer_id_set
  return if internal || customer_id

  raise Alula::NotConfiguredError,
        'Set your customer_id before making requests to the video API'
end

#ensure_role_setObject



67
68
69
70
71
72
73
74
75
# File 'lib/alula/client_configuration.rb', line 67

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

#ensure_video_api_key_setObject



53
54
55
56
57
58
# File 'lib/alula/client_configuration.rb', line 53

def ensure_video_api_key_set
  return if video_api_key

  raise Alula::NotConfiguredError,
        'Set your video API access token before making requests to the video API'
end

#ensure_video_api_url_setObject



46
47
48
49
50
51
# File 'lib/alula/client_configuration.rb', line 46

def ensure_video_api_url_set
  return unless video_api_url.nil?

  raise Alula::NotConfiguredError,
        'did you forget to set the Alula::Client.config.video_api_url config option?'
end

#roleObject



29
30
31
# File 'lib/alula/client_configuration.rb', line 29

def role
  RequestStore.store['alula_role']
end

#role=(user_type) ⇒ Object

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.



21
22
23
24
25
26
27
# File 'lib/alula/client_configuration.rb', line 21

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