Class: Transform
- Inherits:
-
Object
- Object
- Transform
- Includes:
- TransformUtils
- Defined in:
- lib/filestack/models/filestack_transform.rb
Overview
Class for creating transformation chains and storing them to Filestack
Instance Attribute Summary collapse
-
#external_url ⇒ Object
readonly
Returns the value of attribute external_url.
-
#handle ⇒ Object
readonly
Returns the value of attribute handle.
-
#security ⇒ Object
readonly
Returns the value of attribute security.
Instance Method Summary collapse
-
#av_convert(options) ⇒ Filestack::AV
Converts video or audio based on user-provided parameters.
-
#debug ⇒ Typhoeus::Response
Add debug parameter to get information on transformation image.
-
#filetype_conversion(options) ⇒ Filestack::Transform
Converts one filetype to the other.
-
#initialize(handle: nil, external_url: nil, security: nil, apikey: nil) ⇒ Transform
constructor
A new instance of Transform.
-
#method_missing(method_name, **args) ⇒ Filestack::Transform
Catches method calls and checks to see if they exist in transformation list.
-
#respond_to_missing?(method_name) ⇒ Boolean
Override default method (best practice when overriding method_missing).
-
#store ⇒ Filestack::FilestackFilelink
Stores a transformation URL and returns a filelink.
-
#url ⇒ String
Creates a URL based on transformation instance state.
Methods included from TransformUtils
Constructor Details
#initialize(handle: nil, external_url: nil, security: nil, apikey: nil) ⇒ Transform
Returns a new instance of Transform
9 10 11 12 13 14 15 |
# File 'lib/filestack/models/filestack_transform.rb', line 9 def initialize(handle: nil, external_url: nil, security: nil, apikey: nil) @apikey = apikey @handle = handle @external_url = external_url @security = security @transform_tasks = [] end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, **args) ⇒ Filestack::Transform
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
23 24 25 26 27 28 29 30 31 32 |
# File 'lib/filestack/models/filestack_transform.rb', line 23 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 |
Instance Attribute Details
#external_url ⇒ Object (readonly)
Returns the value of attribute external_url
7 8 9 |
# File 'lib/filestack/models/filestack_transform.rb', line 7 def external_url @external_url end |
#handle ⇒ Object (readonly)
Returns the value of attribute handle
7 8 9 |
# File 'lib/filestack/models/filestack_transform.rb', line 7 def handle @handle end |
#security ⇒ Object (readonly)
Returns the value of attribute security
7 8 9 |
# File 'lib/filestack/models/filestack_transform.rb', line 7 def security @security end |
Instance Method Details
#av_convert(options) ⇒ Filestack::AV
Converts video or audio based on user-provided parameters
51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/filestack/models/filestack_transform.rb', line 51 def av_convert() if @external_url return 'av_convert does not support external URLs. Please upload file first.' end @transform_tasks.push( add_transform_task('video_convert', ) ) response = UploadUtils.make_call(url, 'post') if response.code == 200 return AV.new(url, apikey: @apikey, security: @security) end response.body end |
#debug ⇒ Typhoeus::Response
Add debug parameter to get information on transformation image
68 69 70 71 72 73 |
# File 'lib/filestack/models/filestack_transform.rb', line 68 def debug @transform_tasks.push( add_transform_task('debug') ) UploadUtils.make_call(url, 'get').body end |
#filetype_conversion(options) ⇒ Filestack::Transform
Converts one filetype to the other
39 40 41 42 43 44 |
# File 'lib/filestack/models/filestack_transform.rb', line 39 def filetype_conversion() @transform_tasks.push( add_transform_task('output', ) ) self end |
#respond_to_missing?(method_name) ⇒ Boolean
Override default method (best practice when overriding method_missing)
88 89 90 |
# File 'lib/filestack/models/filestack_transform.rb', line 88 def respond_to_missing?(method_name, *) TransformConfig::TRANSFORMATIONS.include?(method_name.to_s || super) end |
#store ⇒ Filestack::FilestackFilelink
Stores a transformation URL and returns a filelink
78 79 80 81 82 83 84 85 |
# File 'lib/filestack/models/filestack_transform.rb', line 78 def store @transform_tasks.push( add_transform_task('store', {}) ) response = UploadUtils.make_call(url, 'get') handle = response.body['url'].split('/').last FilestackFilelink.new(handle, apikey: @apikey, security: @security) end |
#url ⇒ String
Creates a URL based on transformation instance state
95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 |
# File 'lib/filestack/models/filestack_transform.rb', line 95 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 |