class Transloadit
Implements the Transloadit
REST API in Ruby. Check the {file:README.md README} for usage instructions.
Constants
- VERSION
Attributes
@return [Integer] the duration in seconds that signed API requests
generated from this instance remain valid
@return [String] your Transloadit
auth key
@return [String] your Transloadit
auth secret, for signing requests
Public Class Methods
Creates a new instance of the Transloadit
API.
@param [Hash] options a hash of options, which can be any of: @option options [String] :key your auth key from the
{credentials}[https://transloadit.com/accounts/credentials] page (required)
@option options [String] :secret your auth secret from the
{credentials}[https://transloadit.com/accounts/credentials] page, for signing requests (optional)
# File lib/transloadit.rb, line 41 def initialize(options = {}) self.key = options[:key] self.secret = options[:secret] self.duration = options[:duration] || 5 * 60 self.max_size = options[:max_size] _ensure_key_provided end
Public Instance Methods
Creates a Transloadit::Assembly
ready to be sent to the REST API.
@param [Hash] options additional parameters to send with the assembly
submission; for a full list of parameters, see the official documentation on {templates}[http://transloadit.com/docs/templates].
@option options [Step, Array<Step>] :steps the steps to perform in this
assembly
@option options [String] :notify_url A URL to be POSTed when the assembly
has finished processing
@option options [String] :template_id the ID of a
{template}[https://transloadit.com/templates] to use instead of specifying options here directly
# File lib/transloadit.rb, line 78 def assembly(options = {}) Transloadit::Assembly.new(self, options) end
Gets user billing reports for specified month and year. Defaults to current month or year if corresponding param is not specified.
@param [Integer] month the month for which billing reports should be retrieved.
defaults to current month if not specified.
@param [Integer] year the year for which billing reports should be retrieved.
defaults to current year if not specified.
# File lib/transloadit.rb, line 101 def bill(month = Date.today.month, year = Date.today.year) # convert month to 2 digit format month = format '%02d', month path = "bill/#{year}-#{month}" Transloadit::Request.new(path, self.secret).get({ :auth => self.to_hash }) end
@return [String] a human-readable version of the Transloadit
.
# File lib/transloadit.rb, line 112 def inspect self.to_hash.inspect end
Creates a Transloadit::Step
describing a step in an upload assembly.
@param [String] name the name to give the step @param [String] robot the robot to use in this step (e.g., '/image/resize') @param [Hash] options a hash of options to customize the robot's
operation; see the {online documentation}[http://transloadit.com/docs/building-assembly-instructions] for robot-specific options
@return [Step] the created Step
# File lib/transloadit.rb, line 60 def step(name, robot, options = {}) Transloadit::Step.new(name, robot, options) end
Creates a Transloadit::Template
instance ready to interact with its corresponding REST API.
See the Transloadit
documentation for futher information on Templates and available endpoints.
# File lib/transloadit.rb, line 88 def template(options = {}) Transloadit::Template.new(self, options) end
@return [Hash] a Transloadit-compatible Hash of the instance's contents
# File lib/transloadit.rb, line 119 def to_hash result = { :key => self.key } result.update(:max_size => self.max_size) unless self.max_size.nil? result.update(:expires => _generate_expiry) unless self.secret.nil? result end
@return [String] JSON-encoded String containing the object's hash contents
# File lib/transloadit.rb, line 129 def to_json MultiJson.dump(self.to_hash) end
Private Instance Methods
Raises an ArgumentError if no {#key} has been assigned.
# File lib/transloadit.rb, line 138 def _ensure_key_provided unless self.key raise ArgumentError, 'an authentication key must be provided' end end
Generates an API-compatible request expiration timestamp. Uses the current instance's duration.
@return [String] an API-compatible timestamp
# File lib/transloadit.rb, line 150 def _generate_expiry (Time.now + self.duration).utc.strftime('%Y/%m/%d %H:%M:%S+00:00') end