Class: RingCentralSdk::REST::Configuration

Inherits:
Object
  • Object
show all
Defined in:
lib/ringcentral_sdk/rest/configuration.rb

Overview

Configuration class populated by Client constructor block

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#client_idObject

Returns the value of attribute client_id.



12
13
14
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 12

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



12
13
14
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 12

def client_secret
  @client_secret
end

#headersObject

Returns the value of attribute headers.



12
13
14
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 12

def headers
  @headers
end

#jwtObject

Returns the value of attribute jwt.



12
13
14
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 12

def jwt
  @jwt
end

#load_envObject

Returns the value of attribute load_env.



12
13
14
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 12

def load_env
  @load_env
end

#loggerObject

Returns the value of attribute logger.



12
13
14
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 12

def logger
  @logger
end

#redirect_urlObject

Returns the value of attribute redirect_url.



12
13
14
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 12

def redirect_url
  @redirect_url
end

#retryObject

Returns the value of attribute retry.



12
13
14
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 12

def retry
  @retry
end

#retry_optionsObject

Returns the value of attribute retry_options.



12
13
14
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 12

def retry_options
  @retry_options
end

#server_urlObject

Returns the value of attribute server_url.



12
13
14
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 12

def server_url
  @server_url
end

#tokenObject

Returns the value of attribute token.



12
13
14
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 12

def token
  @token
end

#token_fileObject

Returns the value of attribute token_file.



12
13
14
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 12

def token_file
  @token_file
end

Instance Method Details

#authorize_urlObject



95
96
97
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 95

def authorize_url
  URI.join @server_url, RingCentralSdk::REST::Client::AUTHZ_ENDPOINT
end

#default_loggerObject



29
30
31
32
33
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 29

def default_logger
  logger = Logger.new STDOUT
  logger.level = Logger::WARN
  logger
end

#inflateObject



20
21
22
23
24
25
26
27
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 20

def inflate
  @logger = default_logger if !defined?(@logger) || @logger.nil?
  load_environment if load_env
  inflate_headers
  inflate_retry
  inflate_retry_options
  inflate_token
end

#inflate_headersObject



76
77
78
79
80
81
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 76

def inflate_headers
  @headers = {} unless defined? @headers
  if !@headers.nil? && @headers.is_a?(String) && @headers =~ /^\s*{/
    @headers = MultiJson.decode @headers, symbolize_keys: true
  end
end

#inflate_retryObject



52
53
54
55
56
57
58
59
60
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 52

def inflate_retry
  if !defined?(@retry) || @retry.nil?
    @retry = false
  elsif @retry.is_a? String
    @retry = @retry.to_s.strip.downcase == 'true' ? true : false
  elsif ![true, false].include? @retry
    @retry = @retry ? true : false
  end
end

#inflate_retry_optionsObject



62
63
64
65
66
67
68
69
70
71
72
73
74
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 62

def inflate_retry_options
  if @retry == false
    @retry_options = {}
    return
  end
  if !@retry_options.nil? && @retry_options.to_s =~ /^\s*{/
    @retry_options = MultiJson.decode @retry_options.to_s, symbolize_keys: true
  else
    @retry_options = {}
  end
  @retry_options[:error_codes] = [429, 503, 504] unless @retry_options.key? :error_codes
  @retry_options[:logger] = @logger
end

#inflate_tokenObject



83
84
85
86
87
88
89
90
91
92
93
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 83

def inflate_token
  @token = nil unless defined? @token

  if (@token.nil? || @token.empty?) && !token_file.nil? && !@token_file.empty?
    @token = IO.read @token_file if File.exist? @token_file
  end

  if !defined?(@token) && !@token.nil? && @token.is_a?(String) && @token =~ /^\s*{/
    @token = MultiJson.decode @token
  end
end

#load_environmentObject



35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 35

def load_environment
  Dotenv.load
  @server_url    = ENV['RINGCENTRAL_SERVER_URL']    if ENV.key? 'RINGCENTRAL_SERVER_URL'
  @client_id     = ENV['RINGCENTRAL_CLIENT_ID']     if ENV.key? 'RINGCENTRAL_CLIENT_ID'
  @client_secret = ENV['RINGCENTRAL_CLIENT_SECRET'] if ENV.key? 'RINGCENTRAL_CLIENT_SECRET'
  @redirect_url  = ENV['RINGCENTRAL_REDIRECT_URL']  if ENV.key? 'RINGCENTRAL_REDIRECT_URL'
  # @username      = ENV['RINGCENTRAL_USERNAME']      if ENV.key? 'RINGCENTRAL_USERNAME'
  # @extension     = ENV['RINGCENTRAL_EXTENSION']     if ENV.key? 'RINGCENTRAL_EXTENSION'
  # @password      = ENV['RINGCENTRAL_PASSWORD']      if ENV.key? 'RINGCENTRAL_PASSWORD'
  @jwt           = ENV['RINGCENTRAL_JWT']           if ENV.key? 'RINGCENTRAL_JWT'
  @token         = ENV['RINGCENTRAL_TOKEN']         if ENV.key? 'RINGCENTRAL_TOKEN'
  @token_file    = ENV['RINGCENTRAL_TOKEN_FILE']    if ENV.key? 'RINGCENTRAL_TOKEN_FILE'
  @retry         = ENV['RINGCENTRAL_RETRY']         if ENV.key? 'RINGCENTRAL_RETRY'
  @retry_options = ENV['RINGCENTRAL_RETRY_OPTIONS'] if ENV.key? 'RINGCENTRAL_RETRY_OPTIONS'
  @headers       = ENV['RINGCENTRAL_HEADERS']       if ENV.key? 'RINGCENTRAL_HEADERS'
end