Class: VoiceML::RecordingsResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- VoiceML::RecordingsResource
- Defined in:
- lib/voiceml/resources/recordings.rb
Overview
Account-scoped ‘/Recordings` operations.
Per-call recording start/stop/list lives on CallsResource — this resource handles the account-wide list, single-recording fetch (both metadata and audio), and delete.
Constant Summary collapse
- LIST_FIELDS =
{ 'DateCreated' => :date_created, 'DateCreated<' => :date_created_lt, 'DateCreated>' => :date_created_gt, 'CallSid' => :call_sid, 'ConferenceSid' => :conference_sid, 'IncludeSoftDeleted' => :include_soft_deleted, 'Page' => :page, 'PageSize' => :page_size, 'PageToken' => :page_token }.freeze
- GET_FIELDS =
{ 'IncludeSoftDeleted' => :include_soft_deleted }.freeze
Instance Method Summary collapse
- #delete(recording_sid) ⇒ nil
-
#each(**kwargs) {|VoiceML::Recording| ... } ⇒ Enumerator<VoiceML::Recording>
When no block given.
-
#get(recording_sid, **kwargs) ⇒ VoiceML::Recording
Fetch the metadata JSON for a recording.
-
#get_audio(recording_sid) ⇒ VoiceML::RecordingAudio
Fetch the WAV audio for a recording.
- #list(**kwargs) ⇒ VoiceML::RecordingList
Methods inherited from BaseResource
Constructor Details
This class inherits a constructor from VoiceML::BaseResource
Instance Method Details
#delete(recording_sid) ⇒ nil
84 85 86 87 |
# File 'lib/voiceml/resources/recordings.rb', line 84 def delete(recording_sid) @transport.request(:delete, path('Recordings', recording_sid)) nil end |
#each(**kwargs) {|VoiceML::Recording| ... } ⇒ Enumerator<VoiceML::Recording>
Returns when no block given.
38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/voiceml/resources/recordings.rb', line 38 def each(**kwargs, &block) return enum_for(:each, **kwargs) unless block page_num = kwargs.delete(:page) || 0 loop do chunk = list(**kwargs, page: page_num) chunk.recordings.each(&block) break if chunk.next_page_uri.nil? || chunk.next_page_uri.empty? || chunk.recordings.empty? page_num += 1 end end |
#get(recording_sid, **kwargs) ⇒ VoiceML::Recording
Fetch the metadata JSON for a recording.
52 53 54 55 56 57 |
# File 'lib/voiceml/resources/recordings.rb', line 52 def get(recording_sid, **kwargs) params = form_params(GET_FIELDS, kwargs) Recording.from_hash( @transport.request(:get, path('Recordings', recording_sid), params: params.empty? ? nil : params) ) end |
#get_audio(recording_sid) ⇒ VoiceML::RecordingAudio
Fetch the WAV audio for a recording.
Three server delivery shapes are flattened into one result by following any 302 redirect to S3:
-
‘200 OK` — local file present.
-
‘302 Found` — archived to S3; the SDK follows the presigned URL.
-
‘410 Gone` — local file gone AND no S3 key. Raises `VoiceML::GoneError`.
68 69 70 71 72 73 74 75 76 77 78 79 80 81 |
# File 'lib/voiceml/resources/recordings.rb', line 68 def get_audio(recording_sid) status, content, headers = @transport.fetch_bytes( "#{path('Recordings', recording_sid, suffix: '')}.wav" ) content_type = headers['content-type'] content_type = content_type.first if content_type.is_a?(Array) x_amz_id = headers['x-amz-id-2'] RecordingAudio.new( sid: recording_sid, content: content, content_type: content_type || 'application/octet-stream', via_redirect: status == 200 && !x_amz_id.nil? ) end |
#list(**kwargs) ⇒ VoiceML::RecordingList
30 31 32 33 34 |
# File 'lib/voiceml/resources/recordings.rb', line 30 def list(**kwargs) RecordingList.from_hash( @transport.request(:get, path('Recordings'), params: form_params(LIST_FIELDS, kwargs)) ) end |