From 9da48c1acaf8b46a8f65695d06f2bd8b50315d4c Mon Sep 17 00:00:00 2001 From: pmcnano Date: Wed, 6 May 2020 17:48:21 -0500 Subject: [PATCH] Allow Ticket Attachments Passing an array of files is possible within the params, however if that happens the POST shouldn't happen as a JSON. Checking if the params have the attachments key, and then posting as JSON or as a multi form depending on the case. --- lib/freshdesk/resource.rb | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/freshdesk/resource.rb b/lib/freshdesk/resource.rb index 5d78b30..5e82c7c 100644 --- a/lib/freshdesk/resource.rb +++ b/lib/freshdesk/resource.rb @@ -30,7 +30,11 @@ def json_payload end def post - @resource.post(json_payload, content_type: "application/json") + attachments = @params.keys.map(&:to_s).include?('attachments') + options = attachments ? {} : { content_type: 'application/json' } + payload = attachments ? @params : json_payload + + @resource.post(payload, options) rescue RestClient::Exception => e raise e, api_error_message(e) end