Completed
Push — master ( cadf70...47b0dd )
by John
442:50 queued 418:53
created

Config.load_dotenv()   A

Complexity

Conditions 1

Size

Total Lines 7

Duplication

Lines 0
Ratio 0 %
Metric Value
cc 1
dl 0
loc 7
rs 9.4285
1
require 'dotenv'
2
3
module RingCentralSdk::REST
4
  class Config
5
    attr_accessor :user
6
    attr_accessor :app
7
    attr_accessor :env
8
9
    def load_dotenv
10
      Dotenv.load
11
      load_env_app()
12
      load_env_user()
13
      load_env_rc()
14
      return self
15
    end
16
17
    def load_env_app
18
      ['RC_APP_KEY', 'RC_APP_SECRET', 'RC_APP_SERVER_URL'].each do |var|
19
        if !ENV.key?(var)
20
          fail "environment variable '#{var}' not found"
21
        end
22
      end
23
24
      @app = RingCentralSdk::REST::ConfigApp.new
25
      @app.key = ENV['RC_APP_KEY']
26
      @app.secret = ENV['RC_APP_SECRET']
27
      @app.server_url = ENV['RC_APP_SERVER_URL']
28
    end
29
30
    def load_env_user
31
      ['RC_USER_USERNAME', 'RC_USER_PASSWORD'].each do |var|
32
        if !ENV.key?(var)
33
          fail "environment variable '#{var}' not found"
34
        end
35
      end
36
37
      @user = RingCentralSdk::REST::ConfigUser.new
38
      @user.username = ENV['RC_USER_USERNAME']
39
      @user.extension = ENV['RC_USER_EXTENSION']
40
      @user.password = ENV['RC_USER_PASSWORD']
41
    end
42
43
    def load_env_rc
44
      @env = RingCentralSdk::REST::ConfigEnvRc.new
45
    end
46
  end
47
end
48
49
module RingCentralSdk::REST
50
  class ConfigUser
51
    attr_accessor :username
52
    attr_accessor :extension
53
    attr_accessor :password
54
  end
55
end
56
57
module RingCentralSdk::REST
58
  class ConfigApp
59
    attr_accessor :key
60
    attr_accessor :secret
61
    attr_accessor :server_url
62
  end
63
end
64
65
module RingCentralSdk::REST
66
  class ConfigEnvRc
67
    attr_accessor :data
68
    def initialize
69
      @data = {}
70
      ENV.each do |k,v|
71
        next unless k.index('RC_') == 0
72
        @data[k] = v
73
      end
74
    end
75
  end
76
end
77