Class: Hubspot::Contact
Constant Summary
collapse
- ALL_PATH =
'/contacts/v1/lists/all/contacts/all'
- 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'
Class Method Summary
collapse
Instance Method Summary
collapse
Methods inherited from Resource
#[], #changed?, #changes, #delete, #deleted?, find, from_result, #id, #id=, #initialize, #metadata, #persisted?, #reload, #save, #to_i, #update, update, update!
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
in the class Hubspot::Resource
Class Method Details
.all(opts = {}) ⇒ Object
17
18
19
20
21
22
23
24
25
26
27
|
# File 'lib/hubspot/contact.rb', line 17
def all(opts = {})
Hubspot::PagedCollection.new(opts) do |options, offset, limit|
response = Hubspot::Connection.get_json(
ALL_PATH,
options.merge("count" => limit, "vidOffset" => offset)
)
contacts = response["contacts"].map { |result| from_result(result) }
[contacts, response["vid-offset"], response["has-more"]]
end
end
|
.create(email, properties = {}) ⇒ Object
40
41
42
|
# File 'lib/hubspot/contact.rb', line 40
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
.merge(primary, secondary) ⇒ Object
64
65
66
67
68
69
70
71
72
|
# File 'lib/hubspot/contact.rb', line 64
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
52
53
54
55
56
57
58
59
60
61
62
|
# File 'lib/hubspot/contact.rb', line 52
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
79
80
81
|
# File 'lib/hubspot/contact.rb', line 79
def merge(contact)
self.class.merge(@id, contact.to_i)
end
|
#name ⇒ Object
75
76
77
|
# File 'lib/hubspot/contact.rb', line 75
def name
[firstname, lastname].compact.join(' ')
end
|