Class: Transloadit::Rails::Engine
- Inherits:
-
Rails::Engine
- Object
- Rails::Engine
- Transloadit::Rails::Engine
- Defined in:
- lib/transloadit/rails/engine.rb
Constant Summary collapse
- CONFIG_PATH =
'config/transloadit.yml'
Class Attribute Summary collapse
-
.application ⇒ Object
Returns the value of attribute application.
Class Method Summary collapse
-
.configuration ⇒ Object
Returns the configuration object (read from the YAML config file).
-
.sign(params) ⇒ Object
Signs a request to the Transloadit API.
-
.template(name, options = {}) ⇒ Object
Creates an assembly for the named template.
-
.transloadit(options = {}) ⇒ Object
Returns the Transloadit authentication object.
Class Attribute Details
.application ⇒ Object
Returns the value of attribute application.
24 25 26 |
# File 'lib/transloadit/rails/engine.rb', line 24 def application @application end |
Class Method Details
.configuration ⇒ Object
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, = {}) transloadit = self.transloadit( :max_size => .delete(:max_size) ) template = self.configuration['templates'].try(:fetch, name.to_s) = case template when String { :template_id => template }.merge() when Hash template.merge() end transloadit.assembly() 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( = {}) Transloadit.new( :key => self.configuration['auth']['key'], :secret => self.configuration['auth']['secret'], :duration => self.configuration['auth']['duration'], :max_size => [:max_size] || self.configuration['auth']['max_size'] ) end |