twilio_recordings 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/lib/twilio_recordings.rb +102 -0
- metadata +99 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: f6bf1eede329168be4c864532cf2f29a5927de84
|
4
|
+
data.tar.gz: 1c139b37e95d497dabb063ec24dd16f5f9e9706a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8e83d87cb5a2d120793e707d319f92b1f574ec5f65e8ee6442611bcbedfbbe1c24e7ef52b98bf474eb79e82ed983d85852cc44c759a31c6d5b6874921a1b4174
|
7
|
+
data.tar.gz: 090620f1f336e0de14094c7a0d026ae52b2ddd17a6df998e2e0c3d98f31c01a127e6e5424d95ffad3d4f0af568977b9fc27e8ff106d649b20da73e2a94dbe018
|
@@ -0,0 +1,102 @@
|
|
1
|
+
require 'faraday'
|
2
|
+
require 'typhoeus/adapters/faraday'
|
3
|
+
|
4
|
+
class TwilioRecordings
|
5
|
+
attr_writer :connection
|
6
|
+
|
7
|
+
##
|
8
|
+
# Instantiate a new TwilioRecordings object.
|
9
|
+
#
|
10
|
+
# Example:
|
11
|
+
# >> t = TwilioRecordings.new(account_sid, recording_sids, tmp_dir: './my_tmp_dir')
|
12
|
+
# => #<TwilioRecordings:0x00... >
|
13
|
+
#
|
14
|
+
# Arguments:
|
15
|
+
# account_sid: The Twilio account SID, e.g. "AC12345678901234567890123456789012"
|
16
|
+
# recording_sids: An array of recording SIDs, e.g. ["RE12345678901234567890123456789012"]
|
17
|
+
# tmp_dir: The directory that the recordings will be temporarily downloaded to. (optional, default is '/tmp')
|
18
|
+
def initialize(account_sid, recording_sids, tmp_dir: File.join('','tmp'))
|
19
|
+
@account_sid = account_sid
|
20
|
+
@recording_sids = recording_sids
|
21
|
+
@tmp_dir = tmp_dir
|
22
|
+
@recording_downloads = {}
|
23
|
+
end
|
24
|
+
|
25
|
+
##
|
26
|
+
# Return a list of URL strings based on the account SID and recording SIDs.
|
27
|
+
#
|
28
|
+
# Example:
|
29
|
+
# >> t.twilio_urls
|
30
|
+
# => ["https://api.twilio.com/2010-04-01/Accounts/AC12345678901234567890123456789012/Recordings/RE12345678901234567890123456789012.mp3"]
|
31
|
+
def twilio_urls
|
32
|
+
@recording_sids.map { |r| "https://api.twilio.com/2010-04-01/Accounts/#{@account_sid}/Recordings/#{r}.mp3" }
|
33
|
+
end
|
34
|
+
|
35
|
+
##
|
36
|
+
# Return a list of URL strings based on the account SID and recording SIDs.
|
37
|
+
#
|
38
|
+
# Example:
|
39
|
+
# >> t.twilio_urls
|
40
|
+
# => ["./my_tmp_dir/RE12345678901234567890123456789012.mp3"]
|
41
|
+
def filenames
|
42
|
+
@recording_sids.map { |r| File.join(@tmp_dir, "#{r}.mp3") }
|
43
|
+
end
|
44
|
+
|
45
|
+
##
|
46
|
+
# Return the Faraday connection used to download the recordings.
|
47
|
+
#
|
48
|
+
# Will create a new connection if one has not already been set with connection=.
|
49
|
+
#
|
50
|
+
# Example:
|
51
|
+
# >> t.connection
|
52
|
+
# => #<Faraday::Connection:0x00... >
|
53
|
+
def connection
|
54
|
+
@connection ||= Faraday.new do |faraday|
|
55
|
+
faraday.adapter :typhoeus
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def download_and_join
|
60
|
+
download
|
61
|
+
join
|
62
|
+
end
|
63
|
+
|
64
|
+
##
|
65
|
+
# Download the recordings to @tmp_dir
|
66
|
+
#
|
67
|
+
# Returns self
|
68
|
+
#
|
69
|
+
# Example:
|
70
|
+
# >> t.download
|
71
|
+
# => #<TwilioRecordings:0x00... >
|
72
|
+
def download
|
73
|
+
# download the recordings
|
74
|
+
connection.in_parallel do
|
75
|
+
twilio_urls.zip(filenames).each do |url, filename|
|
76
|
+
@recording_downloads[filename] = connection.get(url)
|
77
|
+
end
|
78
|
+
end
|
79
|
+
|
80
|
+
# write the recordings to file
|
81
|
+
@recording_downloads.each do |filename, response|
|
82
|
+
File.open(filename, 'wb') { |f| f.write(response.body) }
|
83
|
+
end
|
84
|
+
|
85
|
+
self
|
86
|
+
end
|
87
|
+
|
88
|
+
##
|
89
|
+
# Join the recordings together into a single file. Returns the output filename.
|
90
|
+
#
|
91
|
+
# Example:
|
92
|
+
# >> t.join('~/my_file.mp3')
|
93
|
+
# => "~/my_file.mp3"
|
94
|
+
#
|
95
|
+
# Arguments:
|
96
|
+
# output: A string to the filename that the output should be written to. (optional, default is '/tmp/joined_{recording_ids}')
|
97
|
+
def join(output=nil)
|
98
|
+
output ||= File.join(@tmp_dir, "joined_#{@recording_sids.join('_')}.mp3")
|
99
|
+
`cat #{filenames.join(" ")} > #{output}`
|
100
|
+
output
|
101
|
+
end
|
102
|
+
end
|
metadata
ADDED
@@ -0,0 +1,99 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: twilio_recordings
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.3
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Paul Boxley
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2013-11-27 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: typhoeus
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - '>='
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - '>='
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - '>='
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - '>='
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: minitest
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: webmock
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
description: Utility for downloading and joining recordings from Twilio.
|
70
|
+
email: paul@paulboxley.com
|
71
|
+
executables: []
|
72
|
+
extensions: []
|
73
|
+
extra_rdoc_files: []
|
74
|
+
files:
|
75
|
+
- lib/twilio_recordings.rb
|
76
|
+
homepage:
|
77
|
+
licenses: []
|
78
|
+
metadata: {}
|
79
|
+
post_install_message:
|
80
|
+
rdoc_options: []
|
81
|
+
require_paths:
|
82
|
+
- lib
|
83
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
requirements:
|
85
|
+
- - '>='
|
86
|
+
- !ruby/object:Gem::Version
|
87
|
+
version: '0'
|
88
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
89
|
+
requirements:
|
90
|
+
- - '>='
|
91
|
+
- !ruby/object:Gem::Version
|
92
|
+
version: '0'
|
93
|
+
requirements: []
|
94
|
+
rubyforge_project:
|
95
|
+
rubygems_version: 2.0.2
|
96
|
+
signing_key:
|
97
|
+
specification_version: 4
|
98
|
+
summary: TwilioRecordings
|
99
|
+
test_files: []
|