class Hubspot::Engagement
HubSpot
Engagements API
{developers.hubspot.com/docs/methods/engagements/create_engagement}
Constants
- ALL_ENGAGEMENTS_PATH
- ASSOCIATE_ENGAGEMENT_PATH
- CREATE_ENGAGMEMENT_PATH
- ENGAGEMENT_PATH
- GET_ASSOCIATED_ENGAGEMENTS
- RECENT_ENGAGEMENT_PATH
Attributes
associations[R]
attachments[R]
engagement[R]
id[R]
metadata[R]
Public Class Methods
all(opts = {})
click to toggle source
# File lib/hubspot/engagement.rb, line 51 def all(opts = {}) path = ALL_ENGAGEMENTS_PATH response = Hubspot::Connection.get_json(path, opts) result = {} result['engagements'] = response['results'].map { |d| new(d) } result['offset'] = response['offset'] result['hasMore'] = response['hasMore'] return result end
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 104 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 33 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 38 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 83 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 75 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 79 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 23 def initialize(response_hash) @engagement = response_hash["engagement"] @associations = response_hash["associations"] @attachments = response_hash["attachments"] @metadata = response_hash["metadata"] @id = engagement["id"] end
recent(opts = {})
click to toggle source
# File lib/hubspot/engagement.rb, line 63 def recent(opts = {}) path = RECENT_ENGAGEMENT_PATH response = Hubspot::Connection.get_json(path, opts) result = {} result['engagements'] = response['results'].map { |d| new(d) } result['offset'] = response['offset'] result['hasMore'] = response['hasMore'] result end
Public Instance Methods
[](property)
click to toggle source
# File lib/hubspot/engagement.rb, line 126 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 117 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 122 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 134 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