Class: Dotloop::Contact
Constant Summary
collapse
- CONTACT_FIELDS =
%w[firstName lastName email home office
fax address city zipCode state country].freeze
QueryParamHelpers::BATCH_SIZE, QueryParamHelpers::MAX_CONTACTS, QueryParamHelpers::MAX_LOOPS
Instance Attribute Summary collapse
Instance Method Summary
collapse
Constructor Details
#initialize(client:) ⇒ Contact
11
12
13
|
# File 'lib/dotloop/contact.rb', line 11
def initialize(client:)
@client = client
end
|
Instance Attribute Details
#client ⇒ Object
Returns the value of attribute client.
6
7
8
|
# File 'lib/dotloop/contact.rb', line 6
def client
@client
end
|
Instance Method Details
#all(options = {}) ⇒ Object
15
16
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/dotloop/contact.rb', line 15
def all(options = {})
contacts = []
url = '/contact'
(1..MAX_CONTACTS).each do |i|
options[:batch_number] = i
current_contacts = @client.get(url, query_params(options))[:data].map do |contact_attrs|
Dotloop::Models::Contact.new(contact_attrs)
end
contacts += current_contacts
break if current_contacts.size < BATCH_SIZE
end
contacts
end
|
#create(params: {}) ⇒ Object
34
35
36
37
38
39
40
41
42
43
|
# File 'lib/dotloop/contact.rb', line 34
def create(params: {})
data = {}
params.each do |key, value|
CONTACT_FIELDS.include?(key.to_s) || next
data[key] = value
end
contact_data = @client.post("/contact", data)[:data]
Dotloop::Models::Contact.new(contact_data)
end
|
#delete(contact_id:) ⇒ Object
56
57
58
|
# File 'lib/dotloop/contact.rb', line 56
def delete(contact_id:)
@client.delete("/contact/#{contact_id.to_i}")
end
|
#find(contact_id:) ⇒ Object
29
30
31
32
|
# File 'lib/dotloop/contact.rb', line 29
def find(contact_id:)
contact_data = @client.get("/contact/#{contact_id.to_i}")[:data]
Dotloop::Models::Contact.new(contact_data)
end
|
#update(contact_id:, params: {}) ⇒ Object
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/dotloop/contact.rb', line 45
def update(contact_id:, params: {})
data = {}
params.each do |key, value|
CONTACT_FIELDS.include?(key.to_s) || next
data[key] = value
end
contact_data = @client.patch("/contact/#{contact_id.to_i}", data)[:data]
Dotloop::Models::Contact.new(contact_data)
end
|