Sha256: 6e88fd4644cfe4040c553cf31872816cd0460f4af140920013c0b675ad8e4ab3

Contents?: true

Size: 1.18 KB

Versions: 4

Compression:

Stored size: 1.18 KB

Contents

require 'intercom/service/base_service'
require 'intercom/api_operations/load'
require 'intercom/api_operations/list'
require 'intercom/api_operations/find'
require 'intercom/api_operations/save'
require 'intercom/api_operations/delete'
require 'intercom/api_operations/search'

module Intercom
  module Service
    class Contact < BaseService
      include ApiOperations::Load
      include ApiOperations::List
      include ApiOperations::Find
      include ApiOperations::Save
      include ApiOperations::Delete
      include ApiOperations::Search

      def collection_class
        Intercom::Contact
      end

      def collection_proxy_class
        Intercom::BaseCollectionProxy
      end

      def merge(lead, user)
        raise_invalid_merge_error unless lead.role == 'lead' && user.role == 'user'

        response = @client.post('/contacts/merge', from: lead.id, into: user.id)
        raise Intercom::HttpError, 'Http Error - No response entity returned' unless response

        user.from_response(response)
      end

      private def raise_invalid_merge_error
        raise Intercom::InvalidMergeError, 'Merging can only be performed on a lead into a user'
      end
    end
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
intercom-4.1.1 lib/intercom/service/contact.rb
intercom-4.1.0 lib/intercom/service/contact.rb
intercom-4.0.1 lib/intercom/service/contact.rb
intercom-4.0.0 lib/intercom/service/contact.rb