Class: Hubspot::Engagement
- Inherits:
-
Object
- Object
- Hubspot::Engagement
- Defined in:
- lib/hubspot/engagement.rb
Overview
HubSpot Engagements API
http://developers.hubspot.com/docs/methods/engagements/create_engagement
Direct Known Subclasses
Constant Summary collapse
- 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'
Instance Attribute Summary collapse
-
#associations ⇒ Object
readonly
Returns the value of attribute associations.
-
#attachments ⇒ Object
readonly
Returns the value of attribute attachments.
-
#engagement ⇒ Object
readonly
Returns the value of attribute engagement.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#metadata ⇒ Object
readonly
Returns the value of attribute metadata.
Class Method Summary collapse
-
.associate!(engagement_id, object_type, object_vid) ⇒ Object
Associates an engagement with an object https://developers.hubspot.com/docs/methods/engagements/associate_engagement.
- .create!(params = {}) ⇒ Object
- .find(engagement_id) ⇒ Object
- .find_by_association(association_id, association_type) ⇒ Object
- .find_by_company(company_id) ⇒ Object
- .find_by_contact(contact_id) ⇒ Object
Instance Method Summary collapse
- #[](property) ⇒ Object
-
#destroy! ⇒ TrueClass
Archives the engagement in hubspot http://developers.hubspot.com/docs/methods/engagements/delete-engagement.
- #destroyed? ⇒ Boolean
-
#initialize(response_hash) ⇒ Engagement
constructor
A new instance of Engagement.
-
#update!(params) ⇒ Hubspot::Engagement
Updates the properties of an engagement http://developers.hubspot.com/docs/methods/engagements/update_engagement.
Constructor Details
#initialize(response_hash) ⇒ Engagement
Returns a new instance of Engagement.
21 22 23 24 25 26 27 28 |
# 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 |
Instance Attribute Details
#associations ⇒ Object (readonly)
Returns the value of attribute associations.
17 18 19 |
# File 'lib/hubspot/engagement.rb', line 17 def associations @associations end |
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
18 19 20 |
# File 'lib/hubspot/engagement.rb', line 18 def @attachments end |
#engagement ⇒ Object (readonly)
Returns the value of attribute engagement.
16 17 18 |
# File 'lib/hubspot/engagement.rb', line 16 def engagement @engagement end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
15 16 17 |
# File 'lib/hubspot/engagement.rb', line 15 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
19 20 21 |
# File 'lib/hubspot/engagement.rb', line 19 def @metadata end |
Class Method Details
.associate!(engagement_id, object_type, object_vid) ⇒ Object
Associates an engagement with an object https://developers.hubspot.com/docs/methods/engagements/associate_engagement
78 79 80 81 82 83 84 85 |
# 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 = {}) ⇒ Object
31 32 33 34 |
# 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) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 |
# 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) ⇒ Object
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# 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. =~ /not found/ end engagements end |
.find_by_company(company_id) ⇒ Object
49 50 51 |
# 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) ⇒ Object
53 54 55 |
# File 'lib/hubspot/engagement.rb', line 53 def find_by_contact(contact_id) find_by_association contact_id, 'CONTACT' end |
Instance Method Details
#[](property) ⇒ Object
100 101 102 |
# File 'lib/hubspot/engagement.rb', line 100 def [](property) @properties[property] end |
#destroy! ⇒ TrueClass
Archives the engagement in hubspot http://developers.hubspot.com/docs/methods/engagements/delete-engagement
91 92 93 94 |
# File 'lib/hubspot/engagement.rb', line 91 def destroy! Hubspot::Connection.delete_json(ENGAGEMENT_PATH, {engagement_id: id}) @destroyed = true end |
#destroyed? ⇒ Boolean
96 97 98 |
# File 'lib/hubspot/engagement.rb', line 96 def destroyed? !!@destroyed end |
#update!(params) ⇒ Hubspot::Engagement
Updates the properties of an engagement http://developers.hubspot.com/docs/methods/engagements/update_engagement
108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/hubspot/engagement.rb', line 108 def update!(params) data = { engagement: params[:engagement] || engagement, associations: params[:associations] || associations, attachments: params[:attachments] || , metadata: params[:metadata] || } Hubspot::Connection.put_json(ENGAGEMENT_PATH, params: { engagement_id: id }, body: data) self end |