Class: Vng::Lead

Inherits:
Resource show all
Defined in:
lib/vng/lead.rb

Overview

Provides methods to interact with Vonigo leads.

Constant Summary collapse

PATH =
'/api/v1/data/Leads/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, name:, email:, phone:, notes:) ⇒ Lead

Returns a new instance of Lead.



10
11
12
13
14
15
16
# File 'lib/vng/lead.rb', line 10

def initialize(id:, name:, email:, phone:, notes:)
  @id = id
  @name = name
  @email = email
  @phone = phone
  @notes = notes
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



8
9
10
# File 'lib/vng/lead.rb', line 8

def email
  @email
end

#idObject (readonly)

Returns the value of attribute id.



8
9
10
# File 'lib/vng/lead.rb', line 8

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



8
9
10
# File 'lib/vng/lead.rb', line 8

def name
  @name
end

#notesObject (readonly)

Returns the value of attribute notes.



8
9
10
# File 'lib/vng/lead.rb', line 8

def notes
  @notes
end

#phoneObject (readonly)

Returns the value of attribute phone.



8
9
10
# File 'lib/vng/lead.rb', line 8

def phone
  @phone
end

Class Method Details

.create(name:, email:, phone:, notes: nil, campaign_option_id: nil) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
# File 'lib/vng/lead.rb', line 18

def self.create(name:, email:, phone:, notes: nil, campaign_option_id: nil)
  body = {
    method: '3',
    Fields: [
       { fieldID: 121, optionID: '59' },
       { fieldID: 126, fieldValue: name },
       { fieldID: 238, fieldValue: URI.encode_uri_component(email) },
       { fieldID: 1024, fieldValue: phone },
    ]
  }

  body[:Fields] << { fieldID: 108, fieldValue: notes } if notes
  body[:Fields] << { fieldID: 795, optionID: campaign_option_id } if campaign_option_id

  data = request path: PATH, body: body

  id = data['Client']['objectID']
  name = value_for_field data, 127
  email = value_for_field data, 238
  phone = value_for_field data, 1024
  notes = value_for_field data, 108

  new id: id, name: name, email: email, phone: phone, notes: notes
end