Class: Transloadit::Assembly
- Inherits:
-
Object
- Object
- Transloadit::Assembly
- 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
-
#options ⇒ Hash
The options describing the Assembly.
-
#transloadit ⇒ Transloadit
readonly
The associated Transloadit instance.
Instance Method Summary collapse
-
#initialize(transloadit, options = {}) ⇒ Assembly
constructor
Creates a new Assembly authenticated using the given
transloadit
instance. -
#inspect ⇒ String
A human-readable version of the Assembly.
-
#steps ⇒ Hash
The processing steps, formatted for sending to Transloadit.
-
#submit!(*ios) ⇒ Object
Submits the assembly for processing.
-
#to_hash ⇒ Hash
A Transloadit-compatible Hash of the Assembly’s contents.
-
#to_json ⇒ String
JSON-encoded String containing the Assembly’s contents.
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, = {}) self.transloadit = transloadit self. = end |
Instance Attribute Details
#options ⇒ Hash
Returns the options describing the Assembly.
18 19 20 |
# File 'lib/transloadit/assembly.rb', line 18 def @options end |
#transloadit ⇒ Transloadit
Returns the associated Transloadit instance.
15 16 17 |
# File 'lib/transloadit/assembly.rb', line 15 def transloadit @transloadit end |
Instance Method Details
#inspect ⇒ String
Returns a human-readable version of the Assembly.
74 75 76 |
# File 'lib/transloadit/assembly.rb', line 74 def inspect self.to_hash.inspect end |
#steps ⇒ Hash
Returns the processing steps, formatted for sending to Transloadit.
36 37 38 |
# File 'lib/transloadit/assembly.rb', line 36 def steps _wrap_steps_in_hash [: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 67 68 69 |
# File 'lib/transloadit/assembly.rb', line 52 def submit!(*ios) params = (ios) payload = { :params => self.to_hash.update(params) } payload.merge!(self.[:fields]) if self.[:fields] # update the payload with file entries ios.each_with_index {|f, i| payload.update :"file_#{i}" => f } # find a bored instance Transloadit::Request.bored! # 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_hash ⇒ Hash
Returns a Transloadit-compatible Hash of the Assembly’s contents.
81 82 83 84 85 86 |
# File 'lib/transloadit/assembly.rb', line 81 def to_hash self..merge( :auth => self.transloadit.to_hash, :steps => self.steps ).delete_if {|k,v| v.nil? || k == :fields} end |
#to_json ⇒ String
Returns JSON-encoded String containing the Assembly’s contents.
91 92 93 |
# File 'lib/transloadit/assembly.rb', line 91 def to_json MultiJson.dump(self.to_hash) end |