Class: Hubspot::Company
- Inherits:
-
Resource
- Object
- Resource
- Hubspot::Company
- Defined in:
- lib/hubspot/company.rb
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'
Class Method Summary collapse
- .add_contact(id, contact_id) ⇒ Object
- .all(opts = {}) ⇒ Object
- .batch_update(companies, opts = {}) ⇒ Object
- .recently_created(opts = {}) ⇒ Object
- .recently_modified(opts = {}) ⇒ Object
- .remove_contact(id, contact_id) ⇒ Object
- .search_domain(domain, opts = {}) ⇒ Object
Instance Method Summary collapse
- #add_contact(contact) ⇒ Object
- #contact_ids(opts = {}) ⇒ Object
- #contacts(opts = {}) ⇒ Object
- #remove_contact(contact) ⇒ Object
Class Method Details
.add_contact(id, contact_id) ⇒ Object
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 |, offset, limit| response = Hubspot::Connection.get_json( ALL_PATH, .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| # Use the specified options or update with the changes changes = opts.empty? ? company.changes : opts unless changes.empty? { "objectId" => company.id, "properties" => changes.map { |k, v| { "name" => k, "value" => v } } } end end # Remove any objects without changes and return if there is nothing to update 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 |, 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 |, 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 |
.remove_contact(id, contact_id) ⇒ Object
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 |, offset, limit| request = { "limit" => limit, "requestOptions" => , "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
#add_contact(contact) ⇒ Object
144 145 146 |
# File 'lib/hubspot/company.rb', line 144 def add_contact(contact) self.class.add_contact(@id, contact.to_i) end |
#contact_ids(opts = {}) ⇒ Object
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 |, offset, limit| response = Hubspot::Connection.get_json( CONTACT_IDS_PATH, {"id" => @id, "vidOffset" => offset, "count" => limit} ) [response["vids"], response["vidOffset"], response["hasMore"]] end end |
#contacts(opts = {}) ⇒ Object
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 |
# File 'lib/hubspot/company.rb', line 117 def contacts(opts = {}) Hubspot::PagedCollection.new(opts) do |, offset, limit| response = Hubspot::Connection.get_json( CONTACTS_PATH, {"id" => @id, "vidOffset" => offset, "count" => limit} ) contacts = response["contacts"].map do |result| result["properties"] = Hubspot::Utils.properties_array_to_hash(result["properties"]) Hubspot::Contact.from_result(result) end [contacts, response["vidOffset"], response["hasMore"]] end end |
#remove_contact(contact) ⇒ Object
148 149 150 |
# File 'lib/hubspot/company.rb', line 148 def remove_contact(contact) self.class.remove_contact(@id, contact.to_i) end |