Class: Transloadit::Assembly
- Inherits:
-
ApiModel
- Object
- ApiModel
- Transloadit::Assembly
- Defined in:
- lib/transloadit/assembly.rb
Overview
Represents an Assembly API ready to make calls to the REST API endpoints.
See the Transloadit documentation for further information on Assemblies and available endpoints.
Constant Summary collapse
- DEFAULT_TRIES =
3
Instance Method Summary collapse
-
#create!(*ios, **params) ⇒ Object
Creates a Transloadit::Assembly and sends to the REST API.
-
#get(id) ⇒ Object
Returns a single assembly object specified by the assembly id.
-
#get_notifications(params = {}) ⇒ Object
Returns all assembly notifications.
-
#list(params = {}) ⇒ Object
Returns a list of all assemblies.
-
#replay(id, params = {}) ⇒ Object
Replays an assembly specified by the id.
-
#replay_notification(id, params = {}) ⇒ Object
Replays an assembly notification by the id.
-
#steps ⇒ Hash
The processing steps, formatted for sending to Transloadit.
-
#submit!(*ios) ⇒ Object
alias for create! keeping this method for backward compatibility.
-
#to_hash ⇒ Hash
A Transloadit-compatible Hash of the Assembly's contents.
Instance Method Details
#create!(*ios) ⇒ Object #create!(*ios, params = {}) ⇒ Object
Creates a Transloadit::Assembly and sends to the REST API. 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 further information on Assemblies and their parameters.
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.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/transloadit/assembly.rb', line 51 def create!(*ios, **params) params[:steps] = _wrap_steps_in_hash(params[:steps]) unless params[:steps].nil? legacy_uploads, = _split_fields([:fields]) if params.key?(:fields) uploads, params[:fields] = _split_fields(params[:fields]) legacy_uploads.merge!(uploads) end unless legacy_uploads.empty? warn "Passing upload IOs in fields is deprecated; use uploads: {name => io} instead." end extra_params = {} [legacy_uploads, params.delete(:uploads) { [:uploads] }].compact.each do |uploads| uploads.each do |name, io| name = name.to_s raise ArgumentError, "Upload name #{name.inspect} is reserved" if %w[params signature].include?(name) raise ArgumentError, "Upload #{name.inspect} must be an IO responding to read" unless io.respond_to?(:read) extra_params[name] = io end end # Keep positional file_N uploads and their precedence for existing callers. ios.each_with_index { |io, i| extra_params["file_#{i}"] = io } upload_positions = _upload_positions(extra_params.values) trials = [:tries] || DEFAULT_TRIES (1..trials).each do |trial| response = _do_request( "/assemblies", params, "post", extra_params ).extend!(Transloadit::Response::Assembly) return response unless response.rate_limit? _handle_rate_limit!(response, upload_positions, trial < trials) end end |
#get(id) ⇒ Object
Returns a single assembly object specified by the assembly id
111 112 113 |
# File 'lib/transloadit/assembly.rb', line 111 def get(id) _do_request("/assemblies/#{id}").extend!(Transloadit::Response::Assembly) end |
#get_notifications(params = {}) ⇒ Object
Returns all assembly notifications
129 130 131 |
# File 'lib/transloadit/assembly.rb', line 129 def get_notifications(params = {}) _do_request "/assembly_notifications", params end |
#list(params = {}) ⇒ Object
Returns a list of all assemblies
103 104 105 |
# File 'lib/transloadit/assembly.rb', line 103 def list(params = {}) _do_request("/assemblies", params) end |
#replay(id, params = {}) ⇒ Object
Replays an assembly specified by the id
120 121 122 123 |
# File 'lib/transloadit/assembly.rb', line 120 def replay(id, params = {}) params[:wait] = false _do_request("/assemblies/#{id}/replay", params, "post").extend!(Transloadit::Response::Assembly) end |
#replay_notification(id, params = {}) ⇒ Object
Replays an assembly notification by the id
138 139 140 |
# File 'lib/transloadit/assembly.rb', line 138 def replay_notification(id, params = {}) _do_request("/assembly_notifications/#{id}/replay", params, "post") end |
#steps ⇒ Hash
Returns the processing steps, formatted for sending to Transloadit.
15 16 17 |
# File 'lib/transloadit/assembly.rb', line 15 def steps _wrap_steps_in_hash [:steps] end |
#submit!(*ios) ⇒ Object
alias for create! keeping this method for backward compatibility
93 94 95 96 97 |
# File 'lib/transloadit/assembly.rb', line 93 def submit!(*ios) warn "#{caller(1..1).first}: warning: Transloadit::Assembly#submit!" \ " is deprecated. use Transloadit::Assembly#create! instead" create!(*ios) end |
#to_hash ⇒ Hash
Returns a Transloadit-compatible Hash of the Assembly's contents.
145 146 147 148 149 150 151 152 153 |
# File 'lib/transloadit/assembly.rb', line 145 def to_hash result = .merge( auth: transloadit.to_hash, steps: steps ) result.delete(:uploads) _, result[:fields] = _split_fields(result[:fields]) if result[:fields] result.delete_if { |_, value| value.nil? } end |