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.

Parameters:

  • transloadit (Transloadit)

    the associated Transloadit instance

  • options (Hash) (defaults to: {})

    the configuration for the Assembly; see Transloadit#assembly


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

Returns the options describing the Assembly.

Returns:

  • (Hash)

    the options describing the Assembly


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

def options
  @options
end

#transloaditTransloadit

Returns the associated Transloadit instance.

Returns:

  • (Transloadit)

    the associated Transloadit instance


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

def transloadit
  @transloadit
end

Instance Method Details

#inspectString

Returns a human-readable version of the Assembly.

Returns:

  • (String)

    a human-readable version of the Assembly


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

def inspect
  self.to_hash.inspect
end

#stepsHash

Returns the processing steps, formatted for sending to Transloadit.

Returns:

  • (Hash)

    the processing steps, formatted for sending to Transloadit


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.

Overloads:

  • #submit!(*ios) ⇒ Object

    Parameters:

    • *ios (Array<IO>)

      the files for the assembly to process

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

    Parameters:

    • *ios (Array<IO>)

      the files for the assembly to process

    • params (Hash) (defaults to: {})

      additional POST data to submit 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

Returns a Transloadit-compatible Hash of the Assembly's contents.

Returns:

  • (Hash)

    a Transloadit-compatible Hash of the Assembly's contents


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

Returns JSON-encoded String containing the Assembly's contents.

Returns:

  • (String)

    JSON-encoded String containing the Assembly's contents


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

def to_json
  MultiJson.dump(self.to_hash)
end