class Hubspot::Engagement
HubSpot
Engagements API
{developers.hubspot.com/docs/methods/engagements/create_engagement}
Constants
- ASSOCIATE_ENGAGEMENT_PATH
- CREATE_ENGAGMEMENT_PATH
- ENGAGEMENT_PATH
- GET_ASSOCIATED_ENGAGEMENTS
Attributes
associations[R]
attachments[R]
engagement[R]
id[R]
metadata[R]
Public Class Methods
associate!(engagement_id, object_type, object_vid)
click to toggle source
Associates an engagement with an object {developers.hubspot.com/docs/methods/engagements/associate_engagement} @param engagement_id [int] id of the engagement to associate @param object_type [string] one of contact, company, or deal @param object_vid [int] id of the contact, company, or deal to associate
# File lib/hubspot/engagement.rb, line 78 def associate!(engagement_id, object_type, object_vid) Hubspot::Connection.put_json(ASSOCIATE_ENGAGEMENT_PATH, params: { engagement_id: engagement_id, object_type: object_type, object_vid: object_vid }) end
create!(params={})
click to toggle source
# File lib/hubspot/engagement.rb, line 31 def create!(params={}) response = Hubspot::Connection.post_json(CREATE_ENGAGMEMENT_PATH, params: {}, body: params ) new(HashWithIndifferentAccess.new(response)) end
find(engagement_id)
click to toggle source
# File lib/hubspot/engagement.rb, line 36 def find(engagement_id) begin response = Hubspot::Connection.get_json(ENGAGEMENT_PATH, { engagement_id: engagement_id }) response ? new(HashWithIndifferentAccess.new(response)) : nil rescue Hubspot::RequestError => ex if ex.response.code == 404 return nil else raise ex end end end
find_by_association(association_id, association_type)
click to toggle source
# File lib/hubspot/engagement.rb, line 57 def find_by_association(association_id, association_type) path = GET_ASSOCIATED_ENGAGEMENTS params = { objectType: association_type, objectId: association_id } raise Hubspot::InvalidParams, 'expecting Integer parameter' unless association_id.try(:is_a?, Integer) raise Hubspot::InvalidParams, 'expecting String parameter' unless association_type.try(:is_a?, String) engagements = [] begin response = Hubspot::Connection.get_json(path, params) engagements = response["results"].try(:map) { |engagement| new(engagement) } rescue => e raise e unless e.message =~ /not found/ end engagements end
find_by_company(company_id)
click to toggle source
# File lib/hubspot/engagement.rb, line 49 def find_by_company(company_id) find_by_association company_id, 'COMPANY' end
find_by_contact(contact_id)
click to toggle source
# File lib/hubspot/engagement.rb, line 53 def find_by_contact(contact_id) find_by_association contact_id, 'CONTACT' end
new(response_hash)
click to toggle source
# File lib/hubspot/engagement.rb, line 21 def initialize(response_hash) @engagement = response_hash["engagement"] @associations = response_hash["associations"] @attachments = response_hash["attachments"] @metadata = response_hash["metadata"] @id = engagement["id"] end
Public Instance Methods
[](property)
click to toggle source
# File lib/hubspot/engagement.rb, line 100 def [](property) @properties[property] end
destroy!()
click to toggle source
Archives the engagement in hubspot {developers.hubspot.com/docs/methods/engagements/delete-engagement} @return [TrueClass] true
# File lib/hubspot/engagement.rb, line 91 def destroy! Hubspot::Connection.delete_json(ENGAGEMENT_PATH, {engagement_id: id}) @destroyed = true end
destroyed?()
click to toggle source
# File lib/hubspot/engagement.rb, line 96 def destroyed? !!@destroyed end
update!(params)
click to toggle source
Updates the properties of an engagement {developers.hubspot.com/docs/methods/engagements/update_engagement} @param params [Hash] hash of properties to update @return [Hubspot::Engagement] self
# File lib/hubspot/engagement.rb, line 108 def update!(params) data = { engagement: params[:engagement] || engagement, associations: params[:associations] || associations, attachments: params[:attachments] || attachments, metadata: params[:metadata] || metadata } Hubspot::Connection.put_json(ENGAGEMENT_PATH, params: { engagement_id: id }, body: data) self end