Sha256: 8aa0000f4d85a535834732aac8e4efd77ac4e7337bf055f7be0cd417c2228408

Contents?: true

Size: 828 Bytes

Versions: 42

Compression:

Stored size: 828 Bytes

Contents

module Services
  module Hubspot
    module Contacts
      class Export
        PROPERTIES_TO_EXPORT = %w[email firstname lastname].freeze

        def initialize(max_pages: 10)
          @max_pages = max_pages
        end

        def call
          convert_to_csv(contacts)
        end

        private

        def contacts
          basic_api = ::Hubspot::Crm::Contacts::BasicApi.new
          basic_api.get_all(auth_names: 'oauth2')
        end

        def convert_to_csv(contacts, properties: PROPERTIES_TO_EXPORT)
          CSV.generate(headers: true) do |csv|
            csv << [:id, *properties]

            contacts.each do |contact|
              csv << [contact.id, *properties.map { |property| contact.properties[property] }]
            end
            csv
          end
        end
      end
    end
  end
end

Version data entries

42 entries across 21 versions & 1 rubygems

Version Path
hubspot-api-client-9.0.0 sample-apps/oauth-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-9.0.0 sample-apps/contacts-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-8.0.1 sample-apps/oauth-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-8.0.1 sample-apps/contacts-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-8.0.0 sample-apps/oauth-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-8.0.0 sample-apps/contacts-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-7.3.0 sample-apps/contacts-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-7.3.0 sample-apps/oauth-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-7.2.0 sample-apps/oauth-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-7.2.0 sample-apps/contacts-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-7.1.1 sample-apps/oauth-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-7.1.1 sample-apps/contacts-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-7.1.0 sample-apps/contacts-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-7.1.0 sample-apps/oauth-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-7.0.0 sample-apps/contacts-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-7.0.0 sample-apps/oauth-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-6.0.0 sample-apps/contacts-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-6.0.0 sample-apps/oauth-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-5.0.0 sample-apps/contacts-app/app/lib/services/hubspot/contacts/export.rb
hubspot-api-client-5.0.0 sample-apps/oauth-app/app/lib/services/hubspot/contacts/export.rb