Completed
Push — master ( 8197d3...5accb3 )
by John
07:20
created

Client   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 42
Duplicated Lines 0 %
Metric Value
dl 0
loc 42
rs 10
wmc 5
1
#!ruby
2
3
require 'multi_json'
4
require 'ringcentral_sdk'
5
require 'voicebase'
6
require 'pp'
7
8
# Set your credentials in the .env file
9
# Use the rc_config_sample.env.txt file as a scaffold
10
11
config = RingCentralSdk::REST::Config.new.load_dotenv
12
13
client = RingCentralSdk::REST::Client.new
14
client.app_config(config.app)
15
client.authorize_user(config.user)
16
17
def transcribe_recordings(rcsdk, vbsdk)
18
  # Retrieve voice call log records with recordings
19
  response = rcsdk.http.get do |req|
20
    params = {:type => 'Voice', :withRecording => 'True',:dateFrom=>'2015-01-01'}
21
    req.url 'account/~/extension/~/call-log', params
22
  end
23
24
  # Save recording and metadata for each call log record
25
  if response.body.has_key?('records')
26
    response.body['records'].each_with_index do |record,i|
27
28
      next unless record.has_key?('recording') &&
29
        record['recording'].has_key?('contentUri')
30
31
      content_uri = record['recording']['contentUri'].to_s
32
33
      content_uri += '?access_token=' + rcsdk.token.token.to_s
34
35
      response_vb = vbsdk.upload_media(:mediaUrl => content_uri.to_s)
36
37
      pp response_vb.body
38
      
39
    end
40
  end
41
end
42
43
vbsdk = VoiceBase::V1::Client.new(
44
  config.env.data['RC_DEMO_VB_API_KEY'],
45
  config.env.data['RC_DEMO_VB_PASSWORD'])
46
47
transcribe_recordings(client, vbsdk)
48
49
puts "DONE"