Sha256: 42c62d37290dd9a76eb12fa806fd3bfbd1f23b7e37f7aa0fcc27ca0e4be00e17

Contents?: true

Size: 1.07 KB

Versions: 15

Compression:

Stored size: 1.07 KB

Contents

module Services
  module Hubspot
    module Associations
      class GetById
        def initialize(company_id)
          @company_id = company_id
        end

        def call
          return unless associated_contacts_id_object.present?

          contacts_list = ::Hubspot::Crm::Contacts::BatchApi.new.read_batch(
            body: associated_contacts_id_object,
            auth_names: 'oauth2'
          ).results
        end

        private

        def associated_contacts_id_object
          id_objects = ::Hubspot::Crm::Associations::BatchApi.new.read_batch(
            'companies',
            'contacts',
            body: company_id_object,
            auth_names: 'oauth2'
          ).results
          id_objects = id_objects.present? ? id_objects[0].to : []
          ::Hubspot::Crm::Contacts::BatchReadInputSimplePublicObjectId.new(inputs: id_objects)
        end

        def company_id_object
          @company_id_object ||= ::Hubspot::Crm::Associations::BatchInputPublicObjectId.new(
            inputs: [@company_id]
          )
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 1 rubygems

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