1
|
|
|
#!ruby |
2
|
|
|
|
3
|
|
|
require 'dotenv' |
4
|
|
|
require 'ringcentral_sdk' |
5
|
|
|
require 'pp' |
6
|
|
|
|
7
|
|
|
Dotenv.load ENV['ENV_PATH'] || '.env' |
8
|
|
|
|
9
|
|
|
# Set your credentials in the .env file |
10
|
|
|
# Use the rc_config_sample.env.txt file as a scaffold |
11
|
|
|
|
12
|
|
|
client = RingCentralSdk::REST::Client.new do |config| |
13
|
|
|
config.server_url = ENV['RINGCENTRAL_SERVER_URL'] |
14
|
|
|
config.app_key = ENV['RINGCENTRAL_CLIENT_ID'] |
15
|
|
|
config.app_secret = ENV['RINGCENTRAL_CLIENT_SECRET'] |
16
|
|
|
config.username = ENV['RINGCENTRAL_USERNAME'] |
17
|
|
|
config.extension = ENV['RINGCENTRAL_EXTENSION'] |
18
|
|
|
config.password = ENV['RINGCENTRAL_PASSWORD'] |
19
|
|
|
end |
20
|
|
|
|
21
|
|
|
def ringout(client, accountId, extensionId, to, from, callerId,playPrompt) |
22
|
|
|
body = { |
23
|
|
|
to: { phoneNumber: to }, |
24
|
|
|
from: { phoneNumber: from }, |
25
|
|
|
callerId: { phoneNumber: callerId }, |
26
|
|
|
playPrompt: playPrompt, |
27
|
|
|
country: {id: 1} |
28
|
|
|
} |
29
|
|
|
client.http.post do |req| |
30
|
|
|
req.url "account/#{accountId}/extension/#{extensionId}/ring-out" |
31
|
|
|
req.headers['Content-Type'] = 'application/json' |
32
|
|
|
req.body = body |
33
|
|
|
end |
34
|
|
|
end |
35
|
|
|
|
36
|
|
|
res = ringout(client, '~', '~', |
37
|
|
|
ENV['RINGCENTRAL_DEMO_RINGOUT_TO'], |
38
|
|
|
ENV['RINGCENTRAL_DEMO_RINGOUT_FROM'], |
39
|
|
|
ENV['RINGCENTRAL_DEMO_RINGOUT_FROM'], |
40
|
|
|
ENV['RINGCENTRAL_DEMO_RINGOUT_PROMPT']) |
41
|
|
|
|
42
|
|
|
puts res.status |
43
|
|
|
pp res.body |
44
|
|
|
|