Class: NPO::Assets::Asset
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- NPO::Assets::Asset
- Defined in:
- lib/npo_assets/asset.rb
Instance Attribute Summary collapse
-
#file ⇒ Object
Returns the value of attribute file.
-
#remote_url ⇒ Object
Returns the value of attribute remote_url.
Class Method Summary collapse
Instance Method Summary collapse
Instance Attribute Details
#file ⇒ Object
Returns the value of attribute file.
4 5 6 |
# File 'lib/npo_assets/asset.rb', line 4 def file @file end |
#remote_url ⇒ Object
Returns the value of attribute remote_url.
4 5 6 |
# File 'lib/npo_assets/asset.rb', line 4 def remote_url @remote_url end |
Class Method Details
.headers(account_name = nil) ⇒ Object
24 25 26 |
# File 'lib/npo_assets/asset.rb', line 24 def headers(account_name=nil) {'X-Account' => account_name || NPO::Assets.account_name} end |
.list(account_name = nil, options = {}) ⇒ Object
10 11 12 13 14 15 16 17 18 19 20 21 22 |
# File 'lib/npo_assets/asset.rb', line 10 def list(account_name=nil, ={}) url = "#{ NPO::Assets.base_url }/assets.xml#{ () }" res = RestClient.get(url, :headers => headers(account_name)) res = Crack::XML.parse(res) if res && res['assets'] res['assets']['asset'].map do |vars| find_or_create_by_url_and_remote_id(vars['url'], vars['id'].to_i) end else [] end end |
Instance Method Details
#url(size = '') ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/npo_assets/asset.rb', line 37 def url(size='') u = attributes['url'] if size == '' # /000/001/002.jpg parts = u else # /000/001/002/320x240.jpg ext = File.extname(u) dir = u.gsub(ext, '') parts = [dir, "#{size}#{ext}"] end File.join(NPO::Assets.base_url, 'assets', parts) end |