Class: MWS::PackingSlip
- Inherits:
-
Object
- Object
- MWS::PackingSlip
- Defined in:
- lib/mws/packing_slip.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 = {}) ⇒ PackingSlip
constructor
A new instance of PackingSlip.
-
#upload ⇒ Object
Upload packing slip to S3.
Constructor Details
#initialize(args = {}) ⇒ PackingSlip
Returns a new instance of PackingSlip.
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/mws/packing_slip.rb', line 26 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.
24 25 26 |
# File 'lib/mws/packing_slip.rb', line 24 def access_key_id @access_key_id end |
#bucket ⇒ Object
Returns the value of attribute bucket.
24 25 26 |
# File 'lib/mws/packing_slip.rb', line 24 def bucket @bucket end |
#secret_access_key ⇒ Object
Returns the value of attribute secret_access_key.
24 25 26 |
# File 'lib/mws/packing_slip.rb', line 24 def secret_access_key @secret_access_key end |
#ship_from_address ⇒ Object
Returns the value of attribute ship_from_address.
24 25 26 |
# File 'lib/mws/packing_slip.rb', line 24 def ship_from_address @ship_from_address end |
#ship_to_address ⇒ Object
Returns the value of attribute ship_to_address.
24 25 26 |
# File 'lib/mws/packing_slip.rb', line 24 def ship_to_address @ship_to_address end |
#shipment_id ⇒ Object
Returns the value of attribute shipment_id.
24 25 26 |
# File 'lib/mws/packing_slip.rb', line 24 def shipment_id @shipment_id end |
#template_url ⇒ Object
Returns the value of attribute template_url.
24 25 26 |
# File 'lib/mws/packing_slip.rb', line 24 def template_url @template_url end |
#url ⇒ Object
Returns the value of attribute url.
24 25 26 |
# File 'lib/mws/packing_slip.rb', line 24 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 |
# File 'lib/mws/packing_slip.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 puts pdf.text_box(@ship_from_address, .merge({:at => [95,392]})) # print to address pdf.text_box(@ship_to_address, .merge({:at => [308,392]})) # print shipment ID pdf.font "Helvetica", :style => :bold, :size => 16 pdf.text_box(@shipment_id, .merge({ :width => 170, :height => 16, :align => :center, :at => [185,250], })) # Generate barcode, store on s3, insert into pdf from S3 = Barby::Code128A.new(@shipment_id).to_png(:height => 60, :width => 142, :margin => 0) = "barcode_#{@shipment_id}.png" AWS::S3::S3Object.store(, , @bucket) = AWS::S3::S3Object.url_for(, @bucket, :expires_in => 3600) pdf.image open(), :at => [200,315] end end |
#upload ⇒ Object
Upload packing slip to S3
77 78 79 80 81 |
# File 'lib/mws/packing_slip.rb', line 77 def upload filename = "packing_slip_#{@shipment_id}.pdf" AWS::S3::S3Object.store(filename, build_pdf.render, @bucket) @url = AWS::S3::S3Object.url_for(filename, @bucket, :expires_in => 3600) end |