Sha256: a565bf79e57cdd8e48daa5b0afc82d103a77adb1645322a6c0aa3a5953a89e98

Contents?: true

Size: 1.53 KB

Versions: 2

Compression:

Stored size: 1.53 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

      def archive(contact)
        @client.post("/#{collection_name}/#{contact.id}/archive", {})
        contact
      end

      def unarchive(contact)
        @client.post("/#{collection_name}/#{contact.id}/unarchive", {})
        contact
      end

      def delete_archived_contact(id)
        @client.delete("/#{collection_name}/#{id}", {})
      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

2 entries across 2 versions & 1 rubygems

Version Path
intercom-4.2.1 lib/intercom/service/contact.rb
intercom-4.2.0 lib/intercom/service/contact.rb