Created
August 23, 2018 08:12
-
-
Save Maroo-b/e41b9a89d40dc37e53f43511178a319b to your computer and use it in GitHub Desktop.
Twilio call logs exporter
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
require "csv" | |
class TwilioCallExporter | |
DATE_FORMAT = "%Y-%m-%d %H:%M UTC" | |
attr_reader :to_phone_number, :start_date | |
def initialize(to_phone_number:, start_date:) | |
@to_phone_number = to_phone_number | |
@start_date = start_date | |
end | |
def export | |
@client = Twilio::REST::Client.new | |
calls = @client.calls.list(to: to_phone_number, start_time_after: start_date) | |
attributes = ["From", "Start Time", "End Time", "Duration", "Status", "Forwarded From"] | |
::CSV.open("export_twilio_calls.csv", "wb") do |csv| | |
csv << attributes | |
calls.each do |res| | |
csv << [ | |
res.from, | |
res.start_time.strftime(DATE_FORMAT), | |
res.end_time.strftime(DATE_FORMAT), | |
res.duration, | |
res.status, | |
res.forwarded_from | |
] | |
end | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment