Completed
Push — master ( 696ecf...30806d )
by John
45s
created

EnvVal()   A

Complexity

Conditions 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
#!ruby
2
3
require 'dotenv'
4
require 'ringcentral_sdk'
5
require 'pp'
6
7
# Set your credentials in the .env file
8
# Use the rc_config_sample.env.txt file as a scaffold
9
10
envPath = ENV['ENV_PATH'] || '.env'
11
puts envPath
12
Dotenv.load envPath
13
14
def EnvVal(envVar)
15
  #envVar = envVar + '_2'
16
  ENV[envVar]
17
end
18
19
client = RingCentralSdk::REST::Client.new do |config|
20
  config.server_url = EnvVal('RINGCENTRAL_SERVER_URL')
21
  config.app_key    = EnvVal('RINGCENTRAL_CLIENT_ID')
22
  config.app_secret = EnvVal('RINGCENTRAL_CLIENT_SECRET')
23
  config.username   = EnvVal('RINGCENTRAL_USERNAME')
24
  config.extension  = EnvVal('RINGCENTRAL_EXTENSION')
25
  config.password   = EnvVal('RINGCENTRAL_PASSWORD')
26
end
27
puts RingCentralSdk::VERSION
28
29
req = RingCentralSdk::REST::Request::Simple.new(
30
  method: 'get',
31
  url: 'account/~/extension/~/message-store',
32
  params: {
33
    direction:   'Outbound',
34
    messageType: 'Fax',
35
    dateFrom:    '2015-01-01T00:00:00Z'
36
  }
37
)
38
39
res = client.send_request req
40
41
pp res.body
42
43
puts '---'
44
45
if 1==0
46
47
res.body['records'].each do |rec|
48
  rec['attachments'].each do |att|
49
    pp att
50
    url = att['uri']
51
    filename = '_fax2_' + url.gsub(%r{^.*restapi/v[^/]+/}, '').gsub(%r{/}, '_')
52
    ext = att['contentType'] == 'application/pdf' ? '.pdf' :
53
      att['contentType'] == 'image/tiff' ? '.tiff' : ''
54
    filename += ext
55
    puts filename
56
57
    response_file = client.http.get url
58
    File.open(filename, 'wb') { |fp| fp.write(response_file.body) }
59
  end
60
end
61
end
62
puts 'DONE'
63