Sha256: f70b2382ea84726edd84a9bd186306894e59809265efcedec5eb993b7f3e464c

Contents?: true

Size: 1.06 KB

Versions: 30

Compression:

Stored size: 1.06 KB

Contents

module Services
  module Hubspot
    module Contacts
      class Search
        def initialize(email:)
          @email = email
        end

        def call
          search_api = ::Hubspot::Crm::Contacts::SearchApi.new
          results = search_api.do_search(body: search_request, auth_names: 'oauth2').results
          results = add_fullnames(results)
          results
        end

        private

        def search_request
          filter = ::Hubspot::Crm::Contacts::Filter.new(
            property_name: 'email',
            operator: 'EQ',
            value: @email
          )
          filter_group = ::Hubspot::Crm::Contacts::FilterGroup.new(filters: [filter])
          ::Hubspot::Crm::Contacts::PublicObjectSearchRequest.new(filter_groups: [filter_group])
        end

        def add_fullnames(contacts)
          contacts.each do |contact|
            fullname = [contact.properties['firstname'], contact.properties['lastname']].reject(&:empty?).join(' ')
            contact.properties['fullname'] = fullname
          end
        end
      end
    end
  end
end

Version data entries

30 entries across 15 versions & 1 rubygems

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