Class: Vng::Contact
Overview
Provides methods to interact with Vonigo contacts.
Constant Summary collapse
- PATH =
'/api/v1/data/Contacts/'
Instance Attribute Summary collapse
-
#client_id ⇒ Object
readonly
Returns the value of attribute client_id.
-
#edited_at ⇒ Object
readonly
Returns the value of attribute edited_at.
-
#email ⇒ Object
readonly
Returns the value of attribute email.
-
#first_name ⇒ Object
readonly
Returns the value of attribute first_name.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#last_name ⇒ Object
readonly
Returns the value of attribute last_name.
-
#phone ⇒ Object
readonly
Returns the value of attribute phone.
Class Method Summary collapse
- .create(first_name:, last_name:, email:, phone:, client_id:) ⇒ Object
- .edited_since(timestamp) ⇒ Object
Instance Method Summary collapse
-
#initialize(id:, first_name:, last_name:, email:, phone:, client_id:, edited_at: nil) ⇒ Contact
constructor
A new instance of Contact.
Constructor Details
#initialize(id:, first_name:, last_name:, email:, phone:, client_id:, edited_at: nil) ⇒ Contact
Returns a new instance of Contact.
10 11 12 13 14 15 16 17 18 |
# File 'lib/vng/contact.rb', line 10 def initialize(id:, first_name:, last_name:, email:, phone:, client_id:, edited_at: nil) @id = id @first_name = first_name @last_name = last_name @email = email @phone = phone @client_id = client_id @edited_at = edited_at end |
Instance Attribute Details
#client_id ⇒ Object (readonly)
Returns the value of attribute client_id.
8 9 10 |
# File 'lib/vng/contact.rb', line 8 def client_id @client_id end |
#edited_at ⇒ Object (readonly)
Returns the value of attribute edited_at.
8 9 10 |
# File 'lib/vng/contact.rb', line 8 def edited_at @edited_at end |
#email ⇒ Object (readonly)
Returns the value of attribute email.
8 9 10 |
# File 'lib/vng/contact.rb', line 8 def email @email end |
#first_name ⇒ Object (readonly)
Returns the value of attribute first_name.
8 9 10 |
# File 'lib/vng/contact.rb', line 8 def first_name @first_name end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
8 9 10 |
# File 'lib/vng/contact.rb', line 8 def id @id end |
#last_name ⇒ Object (readonly)
Returns the value of attribute last_name.
8 9 10 |
# File 'lib/vng/contact.rb', line 8 def last_name @last_name end |
#phone ⇒ Object (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
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 |
# File 'lib/vng/contact.rb', line 40 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, client_id: client_id end |
.edited_since(timestamp) ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/vng/contact.rb', line 20 def self.edited_since() body = { isCompleteObject: 'true', dateStart: .to_i, dateMode: 2 } data = request path: PATH, body: body, returning: 'Contacts' data.filter_map do |body| next unless body['isActive'] id = body['objectID'] first_name = value_for_field body, 127 last_name = value_for_field body, 128 email = value_for_field body, 97 phone = value_for_field body, 96 client_id = value_for_relation body, 'client' edited_at = Time.at Integer(body['dateLastEdited']), in: 'UTC' new id: id, first_name: first_name, last_name: last_name, email: email, phone: phone, client_id: client_id, edited_at: edited_at end end |