Module: Intercom::ApiOperations::Convert

Included in:
Service::Lead
Defined in:
lib/intercom/api_operations/convert.rb

Instance Method Summary collapse

Instance Method Details

#convert(contact, user = false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/intercom/api_operations/convert.rb', line 6

def convert(contact, user = false)
  if contact.class == Intercom::Visitor
    visitor = contact
    req = {
      visitor: { user_id: visitor.user_id },
    }
    if user
      req[:user] = identity_hash(user)
      req[:type] = 'user'
    else
      req[:type] = 'lead'
    end
    Intercom::User.new.from_response(
      @client.post(
        "/visitors/convert", req
      )
    )
  else
    Intercom::User.new.from_response(
      @client.post(
        "/contacts/convert", {
          contact: { user_id: contact.user_id },
          user: identity_hash(user)
        }
      )
    )
  end
end