Sha256: 49bf8edcfe3e6ee419a48687770a135eff798062e5464cd7b8fb7289b3e89193

Contents?: true

Size: 1.34 KB

Versions: 41

Compression:

Stored size: 1.34 KB

Contents

require 'intercom/utils'

module Intercom
  module ApiOperations
    module Bulk
      module Submit
        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

        private

        def item_for_api(method, data_type, item)
          {
            method: method,
            data_type: data_type,
            data: item
          }
        end
      end
    end
  end
end

Version data entries

41 entries across 41 versions & 1 rubygems

Version Path
intercom-4.2.1 lib/intercom/api_operations/bulk/submit.rb
intercom-4.2.0 lib/intercom/api_operations/bulk/submit.rb
intercom-4.1.3 lib/intercom/api_operations/bulk/submit.rb
intercom-4.1.2 lib/intercom/api_operations/bulk/submit.rb
intercom-4.1.1 lib/intercom/api_operations/bulk/submit.rb
intercom-4.1.0 lib/intercom/api_operations/bulk/submit.rb
intercom-4.0.1 lib/intercom/api_operations/bulk/submit.rb
intercom-4.0.0 lib/intercom/api_operations/bulk/submit.rb
intercom-3.9.5 lib/intercom/api_operations/bulk/submit.rb
intercom-3.9.4 lib/intercom/api_operations/bulk/submit.rb
intercom-3.9.3 lib/intercom/api_operations/bulk/submit.rb
intercom-3.9.2 lib/intercom/api_operations/bulk/submit.rb
intercom-3.9.0 lib/intercom/api_operations/bulk/submit.rb
intercom-3.8.1 lib/intercom/api_operations/bulk/submit.rb
intercom-3.8.0 lib/intercom/api_operations/bulk/submit.rb
intercom-3.7.7 lib/intercom/api_operations/bulk/submit.rb
intercom-3.7.6 lib/intercom/api_operations/bulk/submit.rb
intercom-3.7.5 lib/intercom/api_operations/bulk/submit.rb
intercom-3.7.4 lib/intercom/api_operations/bulk/submit.rb
intercom-3.7.3 lib/intercom/api_operations/bulk/submit.rb