-
-
Save anonymous/b48fe0ac6409f08d4da4 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
module Downloader::Core | |
class Asset < Downloader::Asset | |
def fetch_print_files | |
filename = File.join Settings.dir.assets, task.id | |
return if File.exists? filename | |
files = Api.print_files_for task.id | |
File.binwrite filename, files | |
end | |
def fetch_thumbnail | |
thumb_url = thumbnail_url | |
if thumb_url | |
filename = File.join Settings.dir.thumbs, "th_#{task.id}" | |
return if File.exists? filename | |
response = HTTParty.get thumb_url | |
File.binwrite filename, response.body | |
end | |
end | |
def thumbnail_url | |
return nil unless url_thumb.present? | |
Api.concat_url Settings.downloader.thumb_url, url_thumb | |
end | |
def xml | |
asset_xml = order.xml.at_xpath ".//order-item/id[@type='integer'][text()='#{task.asset_no}']/.." | |
return asset_xml if asset_xml | |
# The order XML is supposed to never change. It does, however, in simulation. | |
# Refresh order just in case it ever does in production. | |
order.refresh | |
xml | |
end | |
def download | |
super if task.quantity == '1' | |
end | |
def init_order | |
Order.find task.order_no | |
end | |
# YR 12/27/2015 added getter for short order_id, just the middle section | |
def short_order_id | |
order_id.split('-')[1] | |
end | |
def init_attributes | |
self.buildsheet_config = buildsheet_config_by_sku | |
self.vendor = order.xml.at_xpath('./order/vendor').try :content | |
self.type = xml.at_xpath('./product-id').try(:content).try :to_i | |
self.order_id = task.order_no | |
self.asset_id = task.asset_no | |
self.quantity = xml.at_xpath('./quantity').try(:content).try :to_i | |
self.filename = task.id | |
self.url_original = xml.at_xpath('./asset-url').try :content | |
self.url_thumb = xml.at_xpath('./rendered-url').try :content | |
self.priority = vendor =~ /kodak/i ? 2 : 5 | |
self.url_printable = Api.concat_url Settings.api.core.printable_url, task.id | |
self.type_text = xml.at_xpath('./product/title').try :content | |
self.art_name = xml.at_xpath('./artwork-name').try :content | |
self.rotation = xml.at_xpath('./rotation').try(:content).try :to_f | |
self.scale = xml.at_xpath('./scale').try(:content).try :to_f | |
self.x_offset = xml.at_xpath('./x-offset').try(:content).try :to_f | |
self.y_offset = xml.at_xpath('./y-offset').try(:content).try :to_f | |
self.bleed_warn = xml.at_xpath('./bleed-warning').try :content | |
self.created_at = Time.now | |
self.updated_at = Time.now | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment