Class: Vng::Contact

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

Overview

Provides methods to interact with Vonigo contacts.

Constant Summary collapse

PATH =
'/api/v1/data/Contacts/'

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(id:, first_name:, last_name:, email:, phone:) ⇒ Contact

Returns a new instance of Contact.



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

def initialize(id:, first_name:, last_name:, email:, phone:)
  @id = id
  @first_name = first_name
  @last_name = last_name
  @email = email
  @phone = phone
end

Instance Attribute Details

#emailObject (readonly)

Returns the value of attribute email.



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

def email
  @email
end

#first_nameObject (readonly)

Returns the value of attribute first_name.



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

def first_name
  @first_name
end

#idObject (readonly)

Returns the value of attribute id.



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

def id
  @id
end

#last_nameObject (readonly)

Returns the value of attribute last_name.



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

def last_name
  @last_name
end

#phoneObject (readonly)

Returns the value of attribute phone.



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

def phone
  @phone
end

Class Method Details

.create(first_name:, last_name:, email:, phone:, client_id:) ⇒ Object



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

def self.create(first_name:, last_name:, email:, phone:, client_id:)
  body = {
    method: '3',
    clientID: client_id,
    Fields: [
       { fieldID: 127, fieldValue: first_name },
       { fieldID: 128, fieldValue: last_name },
       { fieldID: 97, fieldValue: URI.encode_uri_component(email) },
       { fieldID: 96, fieldValue: phone },
    ]
  }

  data = request path: PATH, body: body

  id = data['Contact']['objectID']
  first_name = value_for_field data, 127
  last_name = value_for_field data, 128
  email = value_for_field data, 97
  phone = value_for_field data, 96

  new id: id, first_name: first_name, last_name: last_name, email: email, phone: phone
end