Class: Scene7::Asset
- Inherits:
-
Object
- Object
- Scene7::Asset
- Defined in:
- lib/scene7/asset.rb
Instance Attribute Summary collapse
-
#attributes ⇒ Object
readonly
Returns the value of attribute attributes.
Class Method Summary collapse
- .create(params) ⇒ Object
- .current_publish_job ⇒ Object
- .find_all_by_name(name) ⇒ Object
- .find_by_name(name) ⇒ Object
- .job_name(name) ⇒ Object
- .publish ⇒ Object
- .stop_publish_job ⇒ Object
Instance Method Summary collapse
- #destroy ⇒ Object
- #handle ⇒ Object
-
#initialize(attributes) ⇒ Asset
constructor
A new instance of Asset.
- #name ⇒ Object
- #rename(new_name) ⇒ Object
Constructor Details
#initialize(attributes) ⇒ Asset
Returns a new instance of Asset.
91 92 93 |
# File 'lib/scene7/asset.rb', line 91 def initialize(attributes) @attributes = attributes end |
Instance Attribute Details
#attributes ⇒ Object (readonly)
Returns the value of attribute attributes.
89 90 91 |
# File 'lib/scene7/asset.rb', line 89 def attributes @attributes end |
Class Method Details
.create(params) ⇒ Object
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/scene7/asset.rb', line 25 def create(params) source_url = params.delete(:source_url) dest_path = params.delete(:dest_path) request = { :company_handle => Client.company_handle, :job_name => job_name(source_url), :upload_urls_job => { :url_array => { :items => { :source_url => source_url, :dest_path => dest_path, :order! => [:source_url, :dest_path] } }, :overwrite => true, :ready_for_publish => true, :create_mask => false, :email_setting => "None", :order! => [:url_array, :overwrite, :ready_for_publish, :create_mask, :email_setting] }, :order! => [:company_handle, :job_name, :upload_urls_job] } Client.perform_request(:submit_job, request) end |
.current_publish_job ⇒ Object
66 67 68 69 70 71 72 73 |
# File 'lib/scene7/asset.rb', line 66 def current_publish_job response = Client.perform_request(:get_active_jobs, { :company_handle => Client.company_handle }) publish_jobs = response.to_hash[:get_active_jobs_return][:job_array][:items].detect{ |item| item[:image_serving_publish_job] } rescue [] publish_jobs[:job_handle] rescue nil end |
.find_all_by_name(name) ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 |
# File 'lib/scene7/asset.rb', line 11 def find_all_by_name(name) response = Client.perform_request(:get_assets_by_name, :company_handle => Client.company_handle, :name_array => {:items => name}, :order! => [:company_handle, :name_array] ) attributes = response.to_hash[:get_assets_by_name_return][:asset_array][:items] rescue [] collection = attributes.is_a?(Array) ? attributes : [attributes] collection.map! { |asset| new(asset) } end |
.find_by_name(name) ⇒ Object
7 8 9 |
# File 'lib/scene7/asset.rb', line 7 def find_by_name(name) find_all_by_name(name).first end |
.job_name(name) ⇒ Object
52 53 54 |
# File 'lib/scene7/asset.rb', line 52 def job_name(name) Digest::SHA1.hexdigest("#{name}#{Time.now.usec}")[0..20] end |
.publish ⇒ Object
75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/scene7/asset.rb', line 75 def publish Client.perform_request(:submit_job, { :company_handle => Client.company_handle, :job_name => job_name("publish-"), :image_serving_publish_job => { :publish_type => "Full", :email_setting => "None", :order! => [:publish_type, :email_setting] }, :order! => [:company_handle, :job_name, :image_serving_publish_job] }) end |
.stop_publish_job ⇒ Object
56 57 58 59 60 61 62 63 64 |
# File 'lib/scene7/asset.rb', line 56 def stop_publish_job if job_handle = current_publish_job Client.perform_request(:stop_job, { :company_handle => Client.company_handle, :job_handle => job_handle, :order! => [:company_handle, :job_handle] }) end end |
Instance Method Details
#destroy ⇒ Object
119 120 121 122 |
# File 'lib/scene7/asset.rb', line 119 def destroy response = Client.perform_request(:delete_asset, :company_handle => Client.company_handle, :asset_handle => handle, :order! => [:company_handle, :asset_handle]) response.http.code == 200 end |
#handle ⇒ Object
115 116 117 |
# File 'lib/scene7/asset.rb', line 115 def handle attributes[:asset_handle] end |
#name ⇒ Object
95 96 97 |
# File 'lib/scene7/asset.rb', line 95 def name attributes[:name] end |
#rename(new_name) ⇒ Object
99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'lib/scene7/asset.rb', line 99 def rename(new_name) response = Client.perform_request(:rename_asset, { :company_handle => Client.company_handle, :asset_handle => handle, :new_name => new_name, :validate_name => true, :rename_files => true, :order! => [:company_handle, :asset_handle, :new_name, :validate_name, :rename_files] }) @attributes[:name] = new_name return true rescue Savon::SOAP::Fault raise "Could not rename the file -- name already taken." end |