7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
|
# File 'lib/intercom/api_operations/bulk/submit.rb', line 7
def submit_bulk_job(params)
raise(ArgumentError, "events do not support bulk delete operations") if collection_class == Intercom::Event && !params.fetch(:delete_items, []).empty?
data_type = Utils.resource_class_to_singular_name(collection_class)
collection_name = Utils.resource_class_to_collection_name(collection_class)
create_items = params.fetch(:create_items, []).map { |item| item_for_api("post", data_type, item) }
delete_items = params.fetch(:delete_items, []).map { |item| item_for_api("delete", data_type, item) }
existing_job_id = params.fetch(:job_id, '')
bulk_request = {
items: create_items + delete_items
}
bulk_request[:job] = { id: existing_job_id } unless existing_job_id.empty?
response = @client.post("/bulk/#{collection_name}", bulk_request)
raise Intercom::HttpError.new('Http Error - No response entity returned') unless response
Intercom::Job.new.from_response(response)
end
|