Sha256: 5c5a1f6e1ee9ccaa26587b7233fa8fd6b32884543dd65ab6194b57cc690c762b
Contents?: true
Size: 1.06 KB
Versions: 5
Compression:
Stored size: 1.06 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_batch( 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
5 entries across 5 versions & 1 rubygems