Class: Twilio::Rails::Phone::AttachRecordingOperation
- Inherits:
-
ApplicationOperation
- Object
- ActiveOperation::Base
- ApplicationOperation
- Twilio::Rails::Phone::AttachRecordingOperation
- Defined in:
- app/operations/twilio/rails/phone/attach_recording_operation.rb
Overview
Called by ReceiveRecordingOperation to download and store the audio file from the URL provided by Twilio.
Instance Method Summary collapse
Instance Method Details
#execute ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'app/operations/twilio/rails/phone/attach_recording_operation.rb', line 10 def execute recording = ::Twilio::Rails.config.recording_class.find(recording_id) if !recording.audio.attached? if recording.url.blank? raise Twilio::Rails::Phone::Error, "[AttachRecordingOperation] Has a blank URL and cannot be fetched recording_id=#{ recording.id }" end response = Faraday.get(recording.url) if response.success? recording.audio.attach(io: StringIO.new(response.body), filename: "recording.wav", content_type: "audio/wav") recording.save! else raise Twilio::Rails::Phone::Error, "[AttachRecordingOperation] Failed to fetch recording recording_id=#{ recording.id } HTTP#{ response.status } from #{ recording.url }" end end end |