Class: Transloadit::Assembly

Inherits:
ApiModel show all
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

#options, #transloadit

Instance Method Summary collapse

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.

Overloads:

  • #create!(*ios) ⇒ Object

    Parameters:

    • *ios (Array<IO>)

      the files for the assembly to process

  • #create!(*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; for a full list of parameters, see the official documentation on templates.

    Options Hash (params):

    • :steps (Step, Array<Step>)

      the steps to perform in this assembly

    • :notify_url (String)

      A URL to be POSTed when the assembly has finished processing

    • :template_id (String)

      the ID of a template to use instead of specifying params here directly



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!(options[:fields]) if options[:fields]

  trials = options[: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

Parameters:

  • id (String)

    id of the desired assembly



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

Parameters:

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

    additional GET data to submit with the request



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

Parameters:

  • additional (Hash)

    GET data to submit with the request



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

Parameters:

  • id (String)

    id of the desired assembly

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

    additional POST data to submit with the request



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

Parameters:

  • id (String)

    id of the desired assembly

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

    additional POST data to submit with the request



118
119
120
# File 'lib/transloadit/assembly.rb', line 118

def replay_notification(id, params = {})
  _do_request("/assembly_notifications/#{id}/replay", params, "post")
end

#stepsHash

Returns the processing steps, formatted for sending to Transloadit.

Returns:

  • (Hash)

    the processing steps, formatted for sending to Transloadit



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

def steps
  _wrap_steps_in_hash options[: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_hashHash

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

Returns:

  • (Hash)

    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
  options.merge(
    auth: transloadit.to_hash,
    steps: steps
  ).delete_if { |k, v| v.nil? }
end