Completed
Push — master ( 30806d...1d3317 )
by John
44s
created

handleResponse()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
c 1
b 0
f 1
dl 0
loc 4
rs 10
1
#!ruby
2
3
require 'dotenv'
4
require 'ringcentral_sdk'
5
require 'pp'
6
7
envPath = ENV['ENV_PATH'] || '.env'
8
Dotenv.load envPath
9
10
# Set your credentials in the .env file
11
# Use the rc_config_sample.env.txt file as a scaffold
12
13
#client = RingCentralSdk::REST::Client.new do |config|
14
#  config.load_env = true
15
#end
16
17
def EnvVal(envVar)
18
  #envVar = envVar + '_2'
19
  ENV[envVar]
20
end
21
22
client = RingCentralSdk::REST::Client.new do |config|
23
  config.server_url = EnvVal('RINGCENTRAL_SERVER_URL')
24
  config.app_key    = EnvVal('RINGCENTRAL_CLIENT_ID')
25
  config.app_secret = EnvVal('RINGCENTRAL_CLIENT_SECRET')
26
  config.username   = EnvVal('RINGCENTRAL_USERNAME')
27
  config.extension  = EnvVal('RINGCENTRAL_EXTENSION')
28
  config.password   = EnvVal('RINGCENTRAL_PASSWORD')
29
end
30
31
def handleResponse(res)
32
  puts res.status
33
  pp res.body
34
end
35
36
def ringout(client, accountId, extensionId, to, from, callerId)
37
  body = {
38
    to:       { phoneNumber: to },
39
    from:     { phoneNumber: from },
40
    callerId: { phoneNumber: callerId },
41
    playPrompt: false
42
  }
43
  client.http.post do |req|
44
    req.url "account/#{accountId}/extension/#{extensionId}/ring-out"
45
    req.headers['Content-Type'] = 'application/json'
46
    req.body = body
47
  end
48
end
49
50
handleResponse ringout(client, '~', '~', '+14155550100', '+16505550100', '+16505550100')
51