lib/itrp/client/attachments.rb in itrp-client-1.0.1 vs lib/itrp/client/attachments.rb in itrp-client-1.0.2

- old
+ new

@@ -17,15 +17,26 @@ # retrieve the upload configuration for this record from ITRP storage = @client.get(path =~ /\d+$/ ? path : "#{path}/new", {attachment_upload_token: true}, @client.send(:expand_header))[:storage_upload] report_error("Attachments not allowed for #{path}", raise_exceptions) and return unless storage # upload each attachment and store the {key, filesize} has in the note_attachments parameter - data[:note_attachments] = attachments.map {|attachment| upload_attachment(storage, attachment, raise_exceptions) }.compact.to_json + data[attachments_field(path)] = attachments.map {|attachment| upload_attachment(storage, attachment, raise_exceptions) }.compact.to_json end private + def attachments_field(path) + case path + when /cis/, /contracts/, /flsas/, /service_instances/, /slas/ + :remarks_attachments + when /service_offerings/ + :summary_attachments + else + :note_attachments + end + end + def report_error(message, raise_exceptions) if raise_exceptions raise Itrp::UploadFailed.new(message) else @client.logger.error{ message } @@ -94,6 +105,6 @@ request.body = data @client.send(:_send, request, domain, port, ssl) end end -end \ No newline at end of file +end