class Transform

Class for creating transformation chains and storing them to Filestack

Attributes

external_url[R]
handle[R]
security[R]

Public Class Methods

new(handle: nil, external_url: nil, security: nil, apikey: nil) click to toggle source
# File lib/filestack/models/filestack_transform.rb, line 10
def initialize(handle: nil, external_url: nil, security: nil, apikey: nil)
  @apikey = apikey
  @handle = handle
  @external_url = external_url
  @security = security
  @transform_tasks = []
end

Public Instance Methods

av_convert(options) click to toggle source

Converts video or audio based on user-provided parameters

@param [Hash] options User-provided parameters

@return [Filestack::AV]

# File lib/filestack/models/filestack_transform.rb, line 52
def av_convert(options)
  if @external_url
    return 'av_convert does not support external URLs. Please upload file first.'
  end
  @transform_tasks.push(
    add_transform_task('video_convert', options)
  )
  response = UploadUtils.make_call(url, 'post')
  if response.code == 200
    return AV.new(url, apikey: @apikey, security: @security)
  end
  JSON.parse(response.body)
end
debug() click to toggle source

Add debug parameter to get information on transformation image

@return [Hash]

# File lib/filestack/models/filestack_transform.rb, line 69
def debug
  @transform_tasks.push(
    add_transform_task('debug')
  )
  response = UploadUtils.make_call(url, 'get')
  JSON.parse(response.body)
end
filetype_conversion(options) click to toggle source

Converts one filetype to the other

@param options

@return [Filestack::Transform]

# File lib/filestack/models/filestack_transform.rb, line 40
def filetype_conversion(options)
  @transform_tasks.push(
    add_transform_task('output', options)
  )
  self
end
method_missing(method_name, **args) click to toggle source

Catches method calls and checks to see if they exist in transformation list

This is to avoid rewriting the same code over and over for transform chaining

@return [Filestack::Transform] or Error

Calls superclass method
# File lib/filestack/models/filestack_transform.rb, line 24
def method_missing(method_name, **args)
  if TransformConfig::TRANSFORMATIONS.include? method_name.to_s
    @transform_tasks.push(
      add_transform_task(method_name, args)
    )
    self
  else
    super
  end
end
respond_to_missing?(method_name, *) click to toggle source

Override default method (best practice when overriding method_missing)

Calls superclass method
# File lib/filestack/models/filestack_transform.rb, line 91
def respond_to_missing?(method_name, *)
  TransformConfig::TRANSFORMATIONS.include?(method_name.to_s || super)
end
store() click to toggle source

Stores a transformation URL and returns a filelink

@return [Filestack::FilestackFilelink]

# File lib/filestack/models/filestack_transform.rb, line 80
def store
  @transform_tasks.push(
    add_transform_task('store', {})
  )
  response = UploadUtils.make_call(url, 'get')
  response_body = JSON.parse(response.body)
  handle = response_body['url'].split('/').last
  FilestackFilelink.new(handle, apikey: @apikey, security: @security)
end
url() click to toggle source

Creates a URL based on transformation instance state

@return [String]

# File lib/filestack/models/filestack_transform.rb, line 98
def url
  base = [FilestackConfig::CDN_URL]
  if @transform_tasks.include? 'debug'
    @transform_tasks.delete('debug')
    base.push('debug')
  end
  base.push(@apikey) if @apikey && @external_url
  if @security
    policy = @security.policy
    signature = @security.signature
    security_string = "security=policy:#{policy},signature:#{signature}"
    base.push(security_string)
  end
  base += @transform_tasks
  base.push(@handle || @external_url)
  base.join('/')
end