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.



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

def client_id
  @client_id
end

#client_secretObject

Returns the value of attribute client_secret.



14
15
16
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 14

def client_secret
  @client_secret
end

#extensionObject

Returns the value of attribute extension.



18
19
20
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 18

def extension
  @extension
end

#headersObject

Returns the value of attribute headers.



24
25
26
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 24

def headers
  @headers
end

#load_envObject

Returns the value of attribute load_env.



23
24
25
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 23

def load_env
  @load_env
end

#loggerObject

Returns the value of attribute logger.



27
28
29
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 27

def logger
  @logger
end

#passwordObject

Returns the value of attribute password.



19
20
21
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 19

def password
  @password
end

#redirect_urlObject

Returns the value of attribute redirect_url.



15
16
17
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 15

def redirect_url
  @redirect_url
end

#retryObject

Returns the value of attribute retry.



25
26
27
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 25

def retry
  @retry
end

#retry_optionsObject

Returns the value of attribute retry_options.



26
27
28
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 26

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.



20
21
22
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 20

def token
  @token
end

#token_fileObject

Returns the value of attribute token_file.



21
22
23
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 21

def token_file
  @token_file
end

#usernameObject

Returns the value of attribute username.



17
18
19
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 17

def username
  @username
end

Instance Method Details

#authorize_urlObject



103
104
105
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 103

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

#default_loggerObject



38
39
40
41
42
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 38

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

#inflateObject



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

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



84
85
86
87
88
89
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 84

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



60
61
62
63
64
65
66
67
68
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 60

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



70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 70

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



91
92
93
94
95
96
97
98
99
100
101
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 91

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



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
# File 'lib/ringcentral_sdk/rest/configuration.rb', line 44

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'
  @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