lib/rsr_group/order.rb in rsr_group-2.1.6 vs lib/rsr_group/order.rb in rsr_group-2.2.0
- old
+ new
@@ -5,10 +5,21 @@
# * Call {#add_recipient}
# * Call {#add_item} for each item on the order
# * Call {#submit!} to send the order
class Order < Base
+ class ResponseStruct < Struct.new(:success, :message, :data)
+
+ # Simple response object to pass along success/falure/messages of any process
+ # Usage:
+ # response = ResponseStruct.new(true)
+ # response = ResponseStruct.new(false, "You did the wrong thing")
+ # response = ResponseStruct.new(true, nil, { result: 200 })
+
+ alias success? success
+ end
+
# @param [Hash] options
# @option options [String] :merchant_number *required*
# @option options [Integer] :sequence_number *required*
# @option options [String] :username *required*
# @option options [String] :password *required*
@@ -85,15 +96,19 @@
connect(@credentials) do |ftp|
ftp.chdir(RsrGroup.config.submission_dir)
io = StringIO.new(to_txt)
begin
ftp.storlines("STOR " + filename, io)
+ success = ftp.nlst.include?(filename)
+ @response = ResponseStruct.new(success, nil, modified: ftp.mtime(filename), size: ftp.size(filename))
ensure
io.close
end
ftp.close
end
- true
+ @response || ResponseStruct.new(false)
+ rescue Net::FTPPermError => e
+ return ResponseStruct.new(false, e.message.chomp)
end
private
def header