#
# Example script for downloading recording files
#
require 'rubygems'
require 'plivo'
require 'open-uri'
require 'fileutils'
include Plivo
include Plivo::Exceptions
AUTH_ID = "<auth_id>"
AUTH_TOKEN = "<auth_token>"
api = RestClient.new(AUTH_ID,AUTH_TOKEN)
begin
response = api.recordings.list(
add_time__gt: "2023-04-01 00:00:00",
add_time__lt: "2023-04-30 00:00:00",
limit: 5,
offset: 0
)
puts "Found #{response[:objects].length} recordings."
response[:objects].each do |recording|
recording_url = recording.recording_url
recording_id = recording.recording_id
format = recording.recording_format
puts "Downloading recording: #{recording_url}"
output_file = "recordings/#{recording_id}.#{format}"
# Directory where the recordings will be saved
FileUtils.mkdir_p 'recordings'
begin
# Download the file
open(recording_url) do |file|
File.open(output_file, "wb") do |output|
output.write(file.read)
end
end
puts "Downloaded file to: #{output_file}"
rescue StandardError => e
puts "Error downloading file: #{e.message}"
end
end
rescue PlivoRESTError => e
puts 'Exception: ' + e.message
end