Class: Resizor::ResizorAsset
- Inherits:
-
Object
- Object
- Resizor::ResizorAsset
- Defined in:
- lib/resizor/asset.rb
Direct Known Subclasses
Instance Attribute Summary collapse
-
#height ⇒ Object
Returns the value of attribute height.
-
#id ⇒ Object
Returns the value of attribute id.
-
#mime_type ⇒ Object
Returns the value of attribute mime_type.
-
#name ⇒ Object
Returns the value of attribute name.
-
#path ⇒ Object
Returns the value of attribute path.
-
#size ⇒ Object
Returns the value of attribute size.
-
#width ⇒ Object
Returns the value of attribute width.
Instance Method Summary collapse
- #destroy ⇒ Object
-
#initialize(options = {}) ⇒ ResizorAsset
constructor
A new instance of ResizorAsset.
- #resize_token_for(options = {}) ⇒ Object
- #save_to_resizor(params = {}) ⇒ Object
- #url(options = {}) ⇒ Object
Constructor Details
#initialize(options = {}) ⇒ ResizorAsset
Returns a new instance of ResizorAsset.
5 6 7 |
# File 'lib/resizor/asset.rb', line 5 def initialize(={}) .each { |k,v| send "#{k}=".to_sym, v } end |
Instance Attribute Details
#height ⇒ Object
Returns the value of attribute height.
3 4 5 |
# File 'lib/resizor/asset.rb', line 3 def height @height end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/resizor/asset.rb', line 3 def id @id end |
#mime_type ⇒ Object
Returns the value of attribute mime_type.
3 4 5 |
# File 'lib/resizor/asset.rb', line 3 def mime_type @mime_type end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/resizor/asset.rb', line 3 def name @name end |
#path ⇒ Object
Returns the value of attribute path.
3 4 5 |
# File 'lib/resizor/asset.rb', line 3 def path @path end |
#size ⇒ Object
Returns the value of attribute size.
3 4 5 |
# File 'lib/resizor/asset.rb', line 3 def size @size end |
#width ⇒ Object
Returns the value of attribute width.
3 4 5 |
# File 'lib/resizor/asset.rb', line 3 def width @width end |
Instance Method Details
#destroy ⇒ Object
39 40 41 42 43 44 45 46 |
# File 'lib/resizor/asset.rb', line 39 def destroy if id && id.to_s != '' ret = Resizor.delete("/assets/#{id}.json") if ret.code == 200 return true end end end |
#resize_token_for(options = {}) ⇒ Object
17 18 19 20 |
# File 'lib/resizor/asset.rb', line 17 def resize_token_for(={}) = {:size => '200', :format => 'jpg'}.merge() Digest::SHA1.hexdigest("#{Resizor.api_key}-#{id}-#{[:size]}-#{[:format]}") end |
#save_to_resizor(params = {}) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/resizor/asset.rb', line 22 def save_to_resizor(params = {}) if path && File.exists?(path) ret = Resizor.post('/assets.json', params.merge(:file => File.open(path, 'rb'))) if ret.code == 201 @id = ret.body['asset']['id'] @name = "#{ret.body['asset']['name']}.#{ret.body['asset']['extension']}" @mime_type = ret.body['asset']['mime_type'] @size = ret.body['asset']['file_size'] @width = ret.body['asset']['width'] @height = ret.body['asset']['height'] else return false end end return true end |
#url(options = {}) ⇒ Object
9 10 11 12 13 14 |
# File 'lib/resizor/asset.rb', line 9 def url(={}) = {:size => '200', :format => 'jpg', :cdn_host => !Resizor.cdn_host.nil?}.merge() [:size] = [[:size], "q", .delete(:quality)].join if [:quality] [:cdn_host] ? cdn_compatible_url() : query_string_url() end |