Class: MWS::FBA::ShippingLabel
- Inherits:
-
Object
- Object
- MWS::FBA::ShippingLabel
- Defined in:
- lib/mws/fba_label.rb
Instance Attribute Summary collapse
-
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
-
#bucket ⇒ Object
Returns the value of attribute bucket.
-
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
-
#ship_from_address ⇒ Object
Returns the value of attribute ship_from_address.
-
#ship_to_address ⇒ Object
Returns the value of attribute ship_to_address.
-
#shipment_id ⇒ Object
Returns the value of attribute shipment_id.
-
#template_url ⇒ Object
Returns the value of attribute template_url.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
-
#build_pdf ⇒ Object
Build PDF document and return Prawn::Document, ready to be saved locally or uploaded to S3.
-
#initialize(args = {}) ⇒ ShippingLabel
constructor
A new instance of ShippingLabel.
- #upload ⇒ Object
Constructor Details
#initialize(args = {}) ⇒ ShippingLabel
Returns a new instance of ShippingLabel.
27 28 29 30 31 32 33 34 35 |
# 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 |
Instance Attribute Details
#access_key_id ⇒ Object
Returns the value of attribute access_key_id.
25 26 27 |
# File 'lib/mws/fba_label.rb', line 25 def access_key_id @access_key_id end |
#bucket ⇒ Object
Returns the value of attribute bucket.
25 26 27 |
# File 'lib/mws/fba_label.rb', line 25 def bucket @bucket end |
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
25 26 27 |
# File 'lib/mws/fba_label.rb', line 25 def secret_access_key @secret_access_key end |
#ship_from_address ⇒ Object
Returns the value of attribute ship_from_address.
25 26 27 |
# File 'lib/mws/fba_label.rb', line 25 def ship_from_address @ship_from_address end |
#ship_to_address ⇒ Object
Returns the value of attribute ship_to_address.
25 26 27 |
# File 'lib/mws/fba_label.rb', line 25 def ship_to_address @ship_to_address end |
#shipment_id ⇒ Object
Returns the value of attribute shipment_id.
25 26 27 |
# File 'lib/mws/fba_label.rb', line 25 def shipment_id @shipment_id end |
#template_url ⇒ Object
Returns the value of attribute template_url.
25 26 27 |
# File 'lib/mws/fba_label.rb', line 25 def template_url @template_url end |
#url ⇒ Object
Returns the value of attribute url.
25 26 27 |
# File 'lib/mws/fba_label.rb', line 25 def url @url end |
Instance Method Details
#build_pdf ⇒ Object
Build PDF document and return Prawn::Document, ready to be saved locally or uploaded to S3
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'lib/mws/fba_label.rb', line 40 def build_pdf Prawn::Document.new(:template => open(@template_url)) do |pdf| = { :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, .merge({:at => [375,498]})) # print to address pdf.font "Helvetica", :style => :bold, :size => 11 pdf.text_box(@ship_to_address, .merge({:at => [540,498], :height => 40})) # print shipment ID pdf.font "Helvetica", :style => :bold, :size => 11 puts pdf.text_box(@shipment_id, .merge({ :width => 170, :height => 16, :align => :center, :at => [455,374], })) # Generate barcode, store on s3, insert into pdf from S3 = Barby::Code128A.new(@shipment_id).to_png(:height => 50, :margin => 0) = "barcode_#{@shipment_id}.png" AWS::S3::S3Object.store(, , @bucket) = AWS::S3::S3Object.url_for(, @bucket, :expires_in => 3600) pdf.image open(), :at => [470,430] end end |
#upload ⇒ Object
77 78 79 80 81 |
# 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 |