Sha256: 3bf530cf8195e52f7aff5283203c78a37329b5cf9a8bfd542f291f87b3305891

Contents?: true

Size: 1.02 KB

Versions: 14

Compression:

Stored size: 1.02 KB

Contents

module Services
  module Hubspot
    module Associations
      class Delete
        def initialize(company_id, contacts_ids)
          @company_id = company_id
          @contacts_ids = contacts_ids
        end

        def call
          ::Hubspot::Crm::Associations::BatchApi.new.archive_batch(
            'companies',
            'contacts',
            batch_input_public_association: association,
            auth_names: 'oauth2'
          )
        end

        private

        def association
          ::Hubspot::Crm::Associations::BatchInputPublicAssociation.new(
            inputs: contacts_to_assotiate
          )
        end

        def contacts_to_assotiate
          @contacts_ids.map do |id|
            ::Hubspot::Crm::Associations::PublicAssociation.new(
              from: ::Hubspot::Crm::Associations::PublicObjectId.new(id: @company_id),
              to: ::Hubspot::Crm::Associations::PublicObjectId.new(id: id),
              type: 'company_to_contact'
            )
          end
        end
      end
    end
  end
end

Version data entries

14 entries across 14 versions & 1 rubygems

Version Path
hubspot-api-client-7.1.0 sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-7.0.0 sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-6.0.0 sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-5.0.0 sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-4.0.0 sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-3.3.0 sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-3.2.0 sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-3.1.1 sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-3.1.0.pre.beta sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-3.0.0.pre.beta sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-2.3.2 sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-2.3.1 sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-2.2.0 sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb
hubspot-api-client-2.1.0 sample-apps/companies-app/app/lib/services/hubspot/associations/delete.rb