Class: Vng::Contact
Overview
Provides methods to interact with Vonigo contacts.
Constant Summary collapse
- PATH =
'/api/v1/data/Contacts/'
Class Method Summary collapse
- .create(first_name:, last_name:, email:, phone:, client_id:) ⇒ Object
- .edited_since(timestamp) ⇒ Object
-
.where(conditions = {}) ⇒ Vng::Relation
The resources matching the conditions.
Instance Method Summary collapse
- #active? ⇒ Boolean
- #client_id ⇒ Object
- #edited_at ⇒ Object
- #email ⇒ Object
- #first_name ⇒ Object
-
#id ⇒ String
The resource’s unique ID.
-
#initialize(data = {}) ⇒ Contact
constructor
A new instance of Contact.
- #last_name ⇒ Object
- #phone ⇒ Object
Constructor Details
#initialize(data = {}) ⇒ Contact
Returns a new instance of Contact.
14 15 16 |
# File 'lib/vng/contact.rb', line 14 def initialize(data = {}) @data = data end |
Class Method Details
.create(first_name:, last_name:, email:, phone:, client_id:) ⇒ Object
65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/vng/contact.rb', line 65 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 new data['Contact'] end |
.edited_since(timestamp) ⇒ Object
57 58 59 60 61 62 63 |
# File 'lib/vng/contact.rb', line 57 def self.edited_since() contacts = where isCompleteObject: 'true', dateStart: .to_i, dateMode: 2 # TODO: select should accept sub-hash, e.g. # .select :date_last_edited, fields: [134, 1036], relations: ['client'] contacts = contacts.select 'dateLastEdited', 'Fields', 'Relations' contacts.lazy.filter(&:active?) end |
.where(conditions = {}) ⇒ Vng::Relation
Returns the resources matching the conditions.
52 53 54 55 |
# File 'lib/vng/contact.rb', line 52 def self.where(conditions = {}) @where ||= Relation.new @where.where conditions end |
Instance Method Details
#active? ⇒ Boolean
23 24 25 |
# File 'lib/vng/contact.rb', line 23 def active? @data['isActive'] != 'false' end |
#client_id ⇒ Object
43 44 45 |
# File 'lib/vng/contact.rb', line 43 def client_id self.class.value_for_relation @data, 'client' end |
#edited_at ⇒ Object
47 48 49 |
# File 'lib/vng/contact.rb', line 47 def edited_at Time.at Integer(@data['dateLastEdited']), in: 'UTC' end |
#email ⇒ Object
35 36 37 |
# File 'lib/vng/contact.rb', line 35 def email self.class.value_for_field @data, 97 end |
#first_name ⇒ Object
27 28 29 |
# File 'lib/vng/contact.rb', line 27 def first_name self.class.value_for_field @data, 127 end |
#id ⇒ String
Returns the resource’s unique ID.
19 20 21 |
# File 'lib/vng/contact.rb', line 19 def id @data['objectID'] end |
#last_name ⇒ Object
31 32 33 |
# File 'lib/vng/contact.rb', line 31 def last_name self.class.value_for_field @data, 128 end |
#phone ⇒ Object
39 40 41 |
# File 'lib/vng/contact.rb', line 39 def phone self.class.value_for_field @data, 96 end |