Class: Hubspot::Company
Constant Summary
collapse
- ALL_PATH =
'/companies/v2/companies/paged'
- BATCH_UPDATE_PATH =
'/companies/v1/batch-async/update'
- CONTACTS_PATH =
'/companies/v2/companies/:id/contacts'
- CONTACT_IDS_PATH =
'/companies/v2/companies/:id/vids'
- CREATE_PATH =
'/companies/v2/companies/'
- DELETE_PATH =
'/companies/v2/companies/:id'
- FIND_PATH =
'/companies/v2/companies/:id'
- RECENTLY_CREATED_PATH =
'/companies/v2/companies/recent/created'
- RECENTLY_MODIFIED_PATH =
'/companies/v2/companies/recent/modified'
- SEARCH_DOMAIN_PATH =
'/companies/v2/domains/:domain/companies'
- UPDATE_PATH =
'/companies/v2/companies/:id'
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, 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
82
83
84
|
# File 'lib/hubspot/company.rb', line 82
def add_contact(id, contact_id)
Hubspot::Association.create("Company", id, "Contact", contact_id)
end
|
.all(opts = {}) ⇒ Object
20
21
22
23
24
25
26
27
28
29
30
31
|
# File 'lib/hubspot/company.rb', line 20
def all(opts = {})
Hubspot::PagedCollection.new(opts) do |options, offset, limit|
response = Hubspot::Connection.get_json(
ALL_PATH,
options.merge(offset: offset, limit: limit)
)
companies = response["companies"].map { |result| from_result(result) }
[companies, response["offset"], response["has-more"]]
end
end
|
.batch_update(companies, opts = {}) ⇒ Object
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
|
# File 'lib/hubspot/company.rb', line 90
def batch_update(companies, opts = {})
request = companies.map do |company|
changes = opts.empty? ? company.changes : opts
unless changes.empty?
{
"objectId" => company.id,
"properties" => changes.map { |k, v| { "name" => k, "value" => v } }
}
end
end
request.compact!
return true if request.empty?
Hubspot::Connection.post_json(
BATCH_UPDATE_PATH,
params: {},
body: request
)
true
end
|
.recently_created(opts = {}) ⇒ Object
56
57
58
59
60
61
62
63
64
65
66
67
|
# File 'lib/hubspot/company.rb', line 56
def recently_created(opts = {})
Hubspot::PagedCollection.new(opts) do |options, offset, limit|
response = Hubspot::Connection.get_json(
RECENTLY_CREATED_PATH,
{offset: offset, count: limit}
)
companies = response["results"].map { |result| from_result(result) }
[companies, response["offset"], response["hasMore"]]
end
end
|
.recently_modified(opts = {}) ⇒ Object
69
70
71
72
73
74
75
76
77
78
79
80
|
# File 'lib/hubspot/company.rb', line 69
def recently_modified(opts = {})
Hubspot::PagedCollection.new(opts) do |options, offset, limit|
response = Hubspot::Connection.get_json(
RECENTLY_MODIFIED_PATH,
{offset: offset, count: limit}
)
companies = response["results"].map { |result| from_result(result) }
[companies, response["offset"], response["hasMore"]]
end
end
|
86
87
88
|
# File 'lib/hubspot/company.rb', line 86
def remove_contact(id, contact_id)
Hubspot::Association.delete("Company", id, "Contact", contact_id)
end
|
.search_domain(domain, opts = {}) ⇒ Object
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
|
# File 'lib/hubspot/company.rb', line 33
def search_domain(domain, opts = {})
Hubspot::PagedCollection.new(opts) do |options, offset, limit|
request = {
"limit" => limit,
"requestOptions" => options,
"offset" => {
"isPrimary" => true,
"companyId" => offset
}
}
response = Hubspot::Connection.post_json(
SEARCH_DOMAIN_PATH,
params: { domain: domain },
body: request
)
companies = response["results"].map { |result| from_result(result) }
[companies, response["offset"]["companyId"], response["hasMore"]]
end
end
|
Instance Method Details
144
145
146
|
# File 'lib/hubspot/company.rb', line 144
def add_contact(contact)
self.class.add_contact(@id, contact.to_i)
end
|
133
134
135
136
137
138
139
140
141
142
|
# File 'lib/hubspot/company.rb', line 133
def contact_ids(opts = {})
Hubspot::PagedCollection.new(opts) do |options, offset, limit|
response = Hubspot::Connection.get_json(
CONTACT_IDS_PATH,
{"id" => @id, "vidOffset" => offset, "count" => limit}
)
[response["vids"], response["vidOffset"], response["hasMore"]]
end
end
|
148
149
150
|
# File 'lib/hubspot/company.rb', line 148
def remove_contact(contact)
self.class.remove_contact(@id, contact.to_i)
end
|