Sha256: 8d1b3ba0b6fcacdf69edb9d4d9554ef28be2e78780fc226e14726e1b0b05788c

Contents?: true

Size: 1.05 KB

Versions: 10

Compression:

Stored size: 1.05 KB

Contents

module Services
  module Hubspot
    module Contacts
      class GetBatch
        def initialize(ids)
          @ids = ids
        end

        def call
          contact_id_objects = ::Hubspot::Crm::Contacts::BatchReadInputSimplePublicObjectId.new(
            inputs: @ids.map { |id| ::Hubspot::Crm::Contacts::SimplePublicObjectId.new(id: id) }
          )
          batch = ::Hubspot::Crm::Contacts::BatchApi.new.read(
            body: contact_id_objects,
            auth_names: 'oauth2'
          ).results

          contact_names = names(batch)
          @ids.map do |id|
            {
              id: id,
              events: Event.where(object_id: id).order(:occured_at),
              name: contact_names[id]
            }
          end
        end

        private

        def names(contact_objects)
          contact_objects ||= []
          contact_objects.each_with_object({}) do |contact, hash|
            hash[contact.id.to_i] = [contact.properties['firstname'], contact.properties['lastname']].join(' ')
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hubspot-api-client-7.1.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/contacts/get_batch.rb
hubspot-api-client-7.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/contacts/get_batch.rb
hubspot-api-client-6.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/contacts/get_batch.rb
hubspot-api-client-5.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/contacts/get_batch.rb
hubspot-api-client-4.0.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/contacts/get_batch.rb
hubspot-api-client-3.3.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/contacts/get_batch.rb
hubspot-api-client-3.2.0 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/contacts/get_batch.rb
hubspot-api-client-3.1.1 sample-apps/webhooks-contacts-app/app/lib/services/hubspot/contacts/get_batch.rb
hubspot-api-client-3.1.0.pre.beta sample-apps/webhooks-contacts-app/app/lib/services/hubspot/contacts/get_batch.rb
hubspot-api-client-3.0.0.pre.beta sample-apps/webhooks-contacts-app/app/lib/services/hubspot/contacts/get_batch.rb