Sha256: 347cc3d541a7884f477563e087fed670f191703f2625e7188ca1c36c041eec5a

Contents?: true

Size: 1.03 KB

Versions: 5

Compression:

Stored size: 1.03 KB

Contents

module Services
  module Hubspot
    module Contacts
      class Search
        def initialize(after:, limit:, search_query:, search_api: nil)
          @after = after
          @limit = limit
          @search_query = search_query
          @search_api = search_api.nil? ? ::Hubspot::Crm::Contacts::SearchApi.new : search_api
        end

        def call
          @search_api.do_search(body: search_request, auth_names: 'oauth2').results
        end

        private

        def search_request
          filter = ::Hubspot::Crm::Contacts::Filter.new(
            property_name: 'hs_object_id',
            operator: 'GT',
            value: @after
          )
          filter_group = ::Hubspot::Crm::Contacts::FilterGroup.new(filters: [filter])
          ::Hubspot::Crm::Contacts::PublicObjectSearchRequest.new(
            query: @search_query,
            limit: @limit,
            filter_groups: [filter_group],
            sorts: [{'propertyName' => 'hs_object_id', 'direction' => 'ASCENDING'}]
          )
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
hubspot-api-client-7.1.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/contacts/search.rb
hubspot-api-client-7.0.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/contacts/search.rb
hubspot-api-client-6.0.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/contacts/search.rb
hubspot-api-client-5.0.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/contacts/search.rb
hubspot-api-client-4.0.0 sample-apps/search-result-paging-app/app/lib/services/hubspot/contacts/search.rb