Class: Transloadit::Rails::Engine

Inherits:
Rails::Engine
  • Object
show all
Defined in:
lib/transloadit/rails/engine.rb

Constant Summary collapse

CONFIG_PATH =
'config/transloadit.yml'

Class Attribute Summary collapse

Class Method Summary collapse

Class Attribute Details

.applicationObject

Returns the value of attribute application.



24
25
26
# File 'lib/transloadit/rails/engine.rb', line 24

def application
  @application
end

Class Method Details

.configurationObject

Returns the configuration object (read from the YAML config file)



30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/transloadit/rails/engine.rb', line 30

def self.configuration
  if !@configuration || ::Rails.env.development?
    path           = self.application.root.join(CONFIG_PATH)
    erb            = ERB.new(path.read)
    erb.filename   = path.to_s
    @configuration = YAML.load(erb.result)
  end

  if @configuration.keys.include?(::Rails.env)
    @configuration = @configuration[::Rails.env]
  end

  @configuration
end

.sign(params) ⇒ Object

Signs a request to the Transloadit API.



85
86
87
# File 'lib/transloadit/rails/engine.rb', line 85

def self.sign(params)
  Transloadit::Request.send :_hmac, self.transloadit.secret, params
end

.template(name, options = {}) ⇒ Object

Creates an assembly for the named template.

name - The String or Symbol template name. options - The Hash options used to refine the Assembly (default: {}):

:steps    - The Hash with Assembly Steps (optional).
:max_size - The Integer maximum size an upload can have in bytes (optional).


66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# File 'lib/transloadit/rails/engine.rb', line 66

def self.template(name, options = {})
  transloadit = self.transloadit(
    :max_size => options.delete(:max_size)
  )

  template = self.configuration['templates'].try(:fetch, name.to_s)
  assembly_options  = case template
                      when String
                        { :template_id => template }.merge(options)
                      when Hash
                        template.merge(options)
                      end

  transloadit.assembly(assembly_options)
end

.transloadit(options = {}) ⇒ Object

Returns the Transloadit authentication object.

options - The Hash options used to refine the auth params (default: {}):

:max_size - The Integer maximum size an upload can have in bytes (optional).


50
51
52
53
54
55
56
57
# File 'lib/transloadit/rails/engine.rb', line 50

def self.transloadit(options = {})
  Transloadit.new(
    :key      => self.configuration['auth']['key'],
    :secret   => self.configuration['auth']['secret'],
    :duration => self.configuration['auth']['duration'],
    :max_size => options[:max_size] || self.configuration['auth']['max_size']
  )
end