17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/vivid_seat_api/listing.rb', line 17
def publish(records)
VividSeatApi.configure_required!
record_with_errors = records.detect{|record| !UploadFilter.new(attrs).valid?}
if record_with_errors
uploader = UploadFilter.new(record_with_errors)
raise PublishError.new(uploader.errors), "Invalid params" unless uploader.valid?
end
begin
file = Tempfile.new("TicketMonsterApi")
file.write("#{UploadFilter::FIELDS.join(",")}\n")
records.each do |record|
ordered_values = UploadFilter::FIELDS.map do |field|
record[field]
end
file.write("#{ordered_values.join(",")}\n")
end
file.flush
Net::FTP.open(VividSeatApi.configuration.ftp_host) do |ftp|
ftp.passive = true
ftp.login(VividSeatApi.configuration.ftp_user, VividSeatApi.configuration.ftp_pass)
ftp.putbinaryfile(file.path, "#{VividSeatApi::CSV_FILENAME}")
end
ensure
file.close!
end
end
|