| Total Complexity | 5 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| 1 | require 'dotenv' |
||
| 45 | module RingCentralSdk::REST |
||
| 46 | class ConfigApp |
||
| 47 | attr_accessor :key |
||
| 48 | attr_accessor :secret |
||
| 49 | attr_accessor :server_url |
||
| 50 | attr_accessor :redirect_url |
||
| 51 | |||
| 52 | def initialize(app_key='', app_secret='', server_url=RingCentralSdk::RC_SERVER_SANDBOX, opts={}) |
||
| 53 | @key = app_key |
||
| 54 | @secret = app_secret |
||
| 55 | @server_url = server_url |
||
| 56 | if opts.key?(:redirect_url) |
||
| 57 | @redirect_url = opts[:redirect_url] |
||
| 58 | elsif opts.key?(:redirect_uri) |
||
| 59 | @redirect_url = opts[:redirect_uri] |
||
| 60 | else |
||
| 61 | @redirect_url = '' |
||
| 62 | end |
||
| 63 | end |
||
| 64 | |||
| 65 | def load_env |
||
| 66 | ['RC_APP_KEY', 'RC_APP_SECRET', 'RC_APP_SERVER_URL', 'RC_APP_REDIRECT_URL'].each do |var| |
||
| 67 | if !ENV.key?(var) |
||
| 68 | fail "environment variable '#{var}' not found" |
||
| 69 | end |
||
| 70 | end |
||
| 71 | |||
| 72 | @key = ENV['RC_APP_KEY'] |
||
| 73 | @secret = ENV['RC_APP_SECRET'] |
||
| 74 | @server_url = ENV['RC_APP_SERVER_URL'] |
||
| 75 | @redirect_url = ENV['RC_APP_REDIRECT_URL'] |
||
| 76 | end |
||
| 77 | |||
| 78 | def to_hash |
||
| 79 | { |
||
| 80 | key: @key, |
||
| 81 | secret: @secret, |
||
| 82 | server_url: @server_url, |
||
| 83 | redirect_url: @redirect_url |
||
| 84 | } |
||
| 85 | end |
||
| 86 | end |
||
| 103 |