lib/bill_hicks/order.rb in bill_hicks-0.2.2 vs lib/bill_hicks/order.rb in bill_hicks-1.0.0

- old
+ new

@@ -7,12 +7,10 @@ # * Call {#submit!} to send the order # # See each method for a list of required options. class Order < Base - ORDER_UPLOAD_DIR = [FTP_DIR, 'toBHC'].join('/') - # @option options [String] :username *required* # @option options [String] :password *required* def initialize(options = {}) requires!(options, :username, :password) @options = options @@ -43,16 +41,19 @@ def add_item(item = {}) requires!(item, :item_number, :quantity, :price) @items << item end + def filename + "#{@header[:purchase_order]}-order.txt" + end + def submit! raise BillHicks::InvalidOrder.new("Must call #add_header before submitting") if @header.nil? raise BillHicks::InvalidOrder.new("Must add items with #add_item before submitting") if @items.empty? - @order_filename = "#{@header[:purchase_order]}-order.txt" - @order_file = Tempfile.new(@order_filename) + @order_file = Tempfile.new(filename) begin CSV.open(@order_file.path, 'w+') do |csv| csv << header_names csv << header_fields csv << items_header @@ -109,11 +110,11 @@ ] end def upload! connect(@options) do |ftp| - ftp.chdir(ORDER_UPLOAD_DIR) - ftp.puttextfile(@order_file.path, @order_filename) + ftp.chdir(BillHicks.config.full_submission_dir) + ftp.puttextfile(@order_file.path, filename) end end end end