Class: 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 futher information on Assemblies and available endpoints.
Constant Summary collapse
- DEFAULT_TRIES =
3
Instance Attribute Summary
Attributes inherited from ApiModel
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.
Methods inherited from ApiModel
#initialize, #inspect, #to_json
Constructor Details
This class inherits a constructor from Transloadit::ApiModel
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 futher 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.
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 |
# File 'lib/transloadit/assembly.rb', line 48 def create!(*ios, **params) params[:steps] = _wrap_steps_in_hash(params[:steps]) unless params[:steps].nil? extra_params = {} extra_params.merge!([:fields]) if [:fields] trials = [:tries] || DEFAULT_TRIES (1..trials).each do |trial| # update the payload with file entries ios.each_with_index { |f, i| extra_params.update "file_#{i}": f } response = _do_request( "/assemblies", params, "post", extra_params ).extend!(Transloadit::Response::Assembly) return response unless response.rate_limit? _handle_rate_limit!(response, ios, trial < trials) end end |
#get(id) ⇒ Object
Returns a single assembly object specified by the assembly id
91 92 93 |
# File 'lib/transloadit/assembly.rb', line 91 def get(id) _do_request("/assemblies/#{id}").extend!(Transloadit::Response::Assembly) end |
#get_notifications(params = {}) ⇒ Object
Returns all assembly notifications
109 110 111 |
# File 'lib/transloadit/assembly.rb', line 109 def get_notifications(params = {}) _do_request "/assembly_notifications", params end |
#list(params = {}) ⇒ Object
Returns a list of all assemblies
83 84 85 |
# File 'lib/transloadit/assembly.rb', line 83 def list(params = {}) _do_request("/assemblies", params) end |
#replay(id, params = {}) ⇒ Object
Replays an assembly specified by the id
100 101 102 103 |
# File 'lib/transloadit/assembly.rb', line 100 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
118 119 120 |
# File 'lib/transloadit/assembly.rb', line 118 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
73 74 75 76 77 |
# File 'lib/transloadit/assembly.rb', line 73 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.
125 126 127 128 129 130 |
# File 'lib/transloadit/assembly.rb', line 125 def to_hash .merge( auth: transloadit.to_hash, steps: steps ).delete_if { |k, v| v.nil? } end |