Class: Hubspot::Contact
Constant Summary
collapse
- ALL_PATH =
'/crm/v3/objects/contacts'
- CREATE_PATH =
'/contacts/v1/contact'
- CREATE_OR_UPDATE_PATH =
'/contacts/v1/contact/createOrUpdate/email/:email'
- DELETE_PATH =
'/contacts/v1/contact/vid/:id'
- FIND_PATH =
'/contacts/v1/contact/vid/:id/profile'
- FIND_BY_EMAIL_PATH =
'/contacts/v1/contact/email/:email/profile'
- FIND_BY_USER_TOKEN_PATH =
'/contacts/v1/contact/utk/:token/profile'
- MERGE_PATH =
'/contacts/v1/contact/merge-vids/:id/'
- SEARCH_PATH =
'/contacts/v1/search/query'
- UPDATE_PATH =
'/contacts/v1/contact/vid/:id/profile'
- BATCH_UPDATE_PATH =
'/contacts/v1/contact/batch'
Instance Attribute Summary
Attributes inherited from Resource
#changes, #id, #metadata, #properties
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Resource
#[], #changed?, create_path, #delete, delete_path, #deleted?, find, find_path, from_result, #initialize, #persisted?, #reload, #save, #to_i, update, #update, update!, update_path
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Hubspot::Resource
Class Method Details
.all(opts = {}) ⇒ Object
18
19
20
21
22
23
24
25
26
27
28
29
|
# File 'lib/hubspot/contact.rb', line 18
def all(opts = {})
Hubspot::PagedCollection.new(opts) do |options, after, limit|
response = Hubspot::Connection.get_json(
ALL_PATH,
options.merge('limit' => limit, 'offset' => after, 'offset_param' => 'after')
)
contacts = response['results'].map { |result| from_result(result) }
after = response.dig('paging', 'next', 'after')
[contacts, after, after.present?]
end
end
|
.batch_update(contacts, opts = {}) ⇒ Object
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
|
# File 'lib/hubspot/contact.rb', line 81
def batch_update(contacts, opts = {})
request = contacts.map do |contact|
changes = opts.empty? ? contact.changes : opts
next if changes.empty?
{
'vid' => contact.id,
'properties' => changes.map { |k, v| { 'property' => k, 'value' => v } }
}
end
request.compact!
return true if request.empty?
Hubspot::Connection.post_json(
BATCH_UPDATE_PATH,
params: {},
body: request
)
true
end
|
.create(email, properties = {}) ⇒ Object
47
48
49
|
# File 'lib/hubspot/contact.rb', line 47
def create(email, properties = {})
super(properties.merge('email' => email))
end
|
.create_or_update(email, properties = {}) ⇒ Object
.find_by_email(email) ⇒ Object
.find_by_user_token(token) ⇒ Object
Also known as:
find_by_utk
.find_by_vid(vid) ⇒ Object
.merge(primary, secondary) ⇒ Object
71
72
73
74
75
76
77
78
79
|
# File 'lib/hubspot/contact.rb', line 71
def merge(primary, secondary)
Hubspot::Connection.post_json(
MERGE_PATH,
params: { id: primary.to_i, no_parse: true },
body: { 'vidToMerge' => secondary.to_i }
)
true
end
|
.search(query, opts = {}) ⇒ Object
59
60
61
62
63
64
65
66
67
68
69
|
# File 'lib/hubspot/contact.rb', line 59
def search(query, opts = {})
Hubspot::PagedCollection.new(opts) do |options, offset, limit|
response = Hubspot::Connection.get_json(
SEARCH_PATH,
options.merge(q: query, offset: offset, count: limit)
)
contacts = response['contacts'].map { |result| from_result(result) }
[contacts, response['offset'], response['has-more']]
end
end
|
Instance Method Details
#merge(contact) ⇒ Object
112
113
114
|
# File 'lib/hubspot/contact.rb', line 112
def merge(contact)
self.class.merge(@id, contact.to_i)
end
|
#name ⇒ Object
108
109
110
|
# File 'lib/hubspot/contact.rb', line 108
def name
[firstname, lastname].compact.join(' ')
end
|