class MWS::FBA::ShippingLabel
Attributes
access_key_id[RW]
bucket[RW]
secret_access_key[RW]
ship_from_address[RW]
ship_to_address[RW]
shipment_id[RW]
template_url[RW]
url[RW]
Public Class Methods
new(args={})
click to toggle source
# File lib/mws/fba_label.rb, line 27 def initialize(args={}) args.each { |k, v| send("#{k}=", v) } AWS::S3::Base.establish_connection!( :access_key_id => @access_key_id, :secret_access_key => @secret_access_key ) upload end
Public Instance Methods
build_pdf()
click to toggle source
Build PDF document and return Prawn::Document, ready to be saved locally or uploaded to S3
# File lib/mws/fba_label.rb, line 40 def build_pdf Prawn::Document.new(:template => open(@template_url)) do |pdf| common_options = { :width => 200, :height => 50, :align => :left, :valign => :top, :overflow => :shrink_to_fit, } # print from address pdf.font "Helvetica", :size => 8 pdf.text_box(@ship_from_address, common_options.merge({:at => [375,498]})) # print to address pdf.font "Helvetica", :style => :bold, :size => 11 pdf.text_box(@ship_to_address, common_options.merge({:at => [540,498], :height => 40})) # print shipment ID pdf.font "Helvetica", :style => :bold, :size => 11 puts pdf.text_box(@shipment_id, common_options.merge({ :width => 170, :height => 16, :align => :center, :at => [455,374], })) # Generate barcode, store on s3, insert into pdf from S3 barcode_png = Barby::Code128A.new(@shipment_id).to_png(:height => 50, :margin => 0) barcode_filename = "barcode_#{@shipment_id}.png" AWS::S3::S3Object.store(barcode_filename, barcode_png, @bucket) barcode_url = AWS::S3::S3Object.url_for(barcode_filename, @bucket, :expires_in => 3600) pdf.image open(barcode_url), :at => [470,430] end end
upload()
click to toggle source
# File lib/mws/fba_label.rb, line 77 def upload filename = "FBA_label_#{@shipment_id}.pdf" AWS::S3::S3Object.store(filename, build_pdf.render, @bucket) @url = AWS::S3::S3Object.url_for(filename, @bucket, :expires_in => 3600) end