class Rocketwheel::Command::Encoder
Attributes
manifest[RW]
response[RW]
root[RW]
Public Class Methods
new(manifest)
click to toggle source
# File lib/rocketwheel/command/encoder.rb, line 9 def initialize(manifest) @manifest = manifest end
Public Instance Methods
encode(files)
click to toggle source
Public: Starts an encoding job, sending the files to transloadit.
# File lib/rocketwheel/command/encoder.rb, line 14 def encode(files) files = files.map { |file| open(file) } @response = transloadit.assembly(assembly).submit! *files end
encoded?()
click to toggle source
# File lib/rocketwheel/command/encoder.rb, line 19 def encoded? response.reload! response.completed? end
store(destination) { |result| ... }
click to toggle source
# File lib/rocketwheel/command/encoder.rb, line 24 def store(destination) response['results'].each do |name, result| result.each do |result| yield result if block_given? folder = File.join(destination, name) FileUtils.mkdir_p(folder) filename = File.join(folder, result['name']) download(result['url'], filename) end end end
Private Instance Methods
assembly()
click to toggle source
# File lib/rocketwheel/command/encoder.rb, line 66 def assembly { 'steps' => custom_steps || default_steps } end
custom_steps()
click to toggle source
# File lib/rocketwheel/command/encoder.rb, line 62 def custom_steps transloadit_config.steps end
default_steps()
click to toggle source
# File lib/rocketwheel/command/encoder.rb, line 58 def default_steps YAML.load(File.read(File.join(Rocketwheel::Command.templates, 'transloadit.yml')))['steps'] end
download(url, destination)
click to toggle source
# File lib/rocketwheel/command/encoder.rb, line 39 def download(url, destination) uri = URI.parse(url) Net::HTTP.start(uri.host) do |http| resp = http.get(uri.path) File.open(destination, 'wb') { |f| f.write(resp.body) } end end
transloadit()
click to toggle source
# File lib/rocketwheel/command/encoder.rb, line 47 def transloadit @transloadit ||= Transloadit.new( :key => transloadit_config.key, :secret => transloadit_config.secret ) end
transloadit_config()
click to toggle source
# File lib/rocketwheel/command/encoder.rb, line 54 def transloadit_config manifest.transloadit end