Class: Transloadit::Assembly

Inherits:
Object
  • Object
show all
Defined in:
lib/transloadit/assembly.rb

Overview

Represents a Assembly ready to be sent to the REST API for processing. An Assembly can contain one or more Steps for processing or point to a server-side template. It's submitted along with a list of files to process, at which point Transloadit will process and store the files according to the rules in the Assembly.

See the Transloadit documentation for futher information on Assemblies and their parameters.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(transloadit, options = {}) ⇒ Assembly

Creates a new Assembly authenticated using the given transloadit instance.


28
29
30
31
# File 'lib/transloadit/assembly.rb', line 28

def initialize(transloadit, options = {})
  self.transloadit = transloadit
  self.options     = options
end

Instance Attribute Details

#optionsHash


18
19
20
# File 'lib/transloadit/assembly.rb', line 18

def options
  @options
end

#transloaditTransloadit


15
16
17
# File 'lib/transloadit/assembly.rb', line 15

def transloadit
  @transloadit
end

Instance Method Details

#inspectString


71
72
73
# File 'lib/transloadit/assembly.rb', line 71

def inspect
  self.to_hash.inspect
end

#stepsHash


36
37
38
# File 'lib/transloadit/assembly.rb', line 36

def steps
  _wrap_steps_in_hash options[:steps]
end

#submit!(*ios) ⇒ Object #submit!(*ios, params = {}) ⇒ Object

Submits the assembly for processing. Accepts as many IO objects as you wish to process in the assembly. The last argument is an optional Hash of parameters to send along with the request.


52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/transloadit/assembly.rb', line 52

def submit!(*ios)
  params  = _extract_options!(ios)
  payload = { :params => self.to_hash.update(params) }
  payload.merge!(self.options[:fields]) if self.options[:fields]

  # update the payload with file entries
  ios.each_with_index {|f, i| payload.update :"file_#{i}" => f }

  # create the request
  request = Transloadit::Request.new '/assemblies',
    self.transloadit.secret

  # post the request, extend it with the Assembly extensions
  request.post(payload).extend!(Transloadit::Response::Assembly)
end

#to_hashHash


78
79
80
81
82
83
# File 'lib/transloadit/assembly.rb', line 78

def to_hash
  self.options.merge(
    :auth  => self.transloadit.to_hash,
    :steps => self.steps
  ).delete_if {|k,v| v.nil?}
end

#to_jsonString


88
89
90
# File 'lib/transloadit/assembly.rb', line 88

def to_json
  MultiJson.dump(self.to_hash)
end