lib/hubspot/engagement.rb in hubspot-ruby-0.4.0 vs lib/hubspot/engagement.rb in hubspot-ruby-0.5.0
- old
+ new
@@ -7,21 +7,24 @@
# {http://developers.hubspot.com/docs/methods/engagements/create_engagement}
#
class Engagement
CREATE_ENGAGMEMENT_PATH = '/engagements/v1/engagements'
ENGAGEMENT_PATH = '/engagements/v1/engagements/:engagement_id'
+ ASSOCIATE_ENGAGEMENT_PATH = '/engagements/v1/engagements/:engagement_id/associations/:object_type/:object_vid'
GET_ASSOCIATED_ENGAGEMENTS = '/engagements/v1/engagements/associated/:objectType/:objectId/paged'
attr_reader :id
attr_reader :engagement
attr_reader :associations
+ attr_reader :attachments
attr_reader :metadata
def initialize(response_hash)
@engagement = response_hash["engagement"]
@associations = response_hash["associations"]
+ @attachments = response_hash["attachments"]
@metadata = response_hash["metadata"]
@id = engagement["id"]
end
class << self
@@ -64,10 +67,24 @@
rescue => e
raise e unless e.message =~ /not found/
end
engagements
end
+
+ # Associates an engagement with an object
+ # {https://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
+ 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
end
# Archives the engagement in hubspot
# {http://developers.hubspot.com/docs/methods/engagements/delete-engagement}
# @return [TrueClass] true
@@ -88,13 +105,14 @@
# {http://developers.hubspot.com/docs/methods/engagements/update_engagement}
# @param params [Hash] hash of properties to update
# @return [Hubspot::Engagement] self
def update!(params)
data = {
- engagement: engagement,
- associations: associations,
- metadata: metadata
+ 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
@@ -108,11 +126,11 @@
def contact_ids
associations['contactIds']
end
class << self
- def create!(contact_id, note_body, owner_id = nil)
+ def create!(contact_id, note_body, owner_id = nil, deal_id = nil)
data = {
engagement: {
type: 'NOTE'
},
associations: {
@@ -123,9 +141,11 @@
}
}
# if the owner id has been provided, append it to the engagement
data[:engagement][:owner_id] = owner_id if owner_id
+ # if the deal id has been provided, associate the note with the deal
+ data[:associations][:dealIds] = [deal_id] if deal_id
super(data)
end
end
end