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
- ALL_ENGAGEMENTS_PATH =
'/engagements/v1/engagements/paged'
- RECENT_ENGAGEMENT_PATH =
'/engagements/v1/engagements/recent/modified'
- 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
- .all(opts = {}) ⇒ Object
-
.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
- .recent(opts = {}) ⇒ 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.
23 24 25 26 27 28 29 |
# 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 |
Instance Attribute Details
#associations ⇒ Object (readonly)
Returns the value of attribute associations.
19 20 21 |
# File 'lib/hubspot/engagement.rb', line 19 def associations @associations end |
#attachments ⇒ Object (readonly)
Returns the value of attribute attachments.
20 21 22 |
# File 'lib/hubspot/engagement.rb', line 20 def @attachments end |
#engagement ⇒ Object (readonly)
Returns the value of attribute engagement.
18 19 20 |
# File 'lib/hubspot/engagement.rb', line 18 def engagement @engagement end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
17 18 19 |
# File 'lib/hubspot/engagement.rb', line 17 def id @id end |
#metadata ⇒ Object (readonly)
Returns the value of attribute metadata.
21 22 23 |
# File 'lib/hubspot/engagement.rb', line 21 def @metadata end |
Class Method Details
.all(opts = {}) ⇒ Object
50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/hubspot/engagement.rb', line 50 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) ⇒ Object
Associates an engagement with an object https://developers.hubspot.com/docs/methods/engagements/associate_engagement
103 104 105 106 107 108 109 110 |
# File 'lib/hubspot/engagement.rb', line 103 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
32 33 34 35 |
# File 'lib/hubspot/engagement.rb', line 32 def create!(params={}) response = Hubspot::Connection.post_json(CREATE_ENGAGMEMENT_PATH, params: {}, body: params ) new(HashWithIndifferentAccess.new(response)) end |
.find(engagement_id) ⇒ Object
37 38 39 40 41 42 43 44 45 46 47 48 |
# File 'lib/hubspot/engagement.rb', line 37 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
82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 |
# File 'lib/hubspot/engagement.rb', line 82 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
74 75 76 |
# File 'lib/hubspot/engagement.rb', line 74 def find_by_company(company_id) find_by_association company_id, 'COMPANY' end |
.find_by_contact(contact_id) ⇒ Object
78 79 80 |
# File 'lib/hubspot/engagement.rb', line 78 def find_by_contact(contact_id) find_by_association contact_id, 'CONTACT' end |
.recent(opts = {}) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 |
# File 'lib/hubspot/engagement.rb', line 62 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 |
Instance Method Details
#[](property) ⇒ Object
125 126 127 |
# File 'lib/hubspot/engagement.rb', line 125 def [](property) @properties[property] end |
#destroy! ⇒ TrueClass
Archives the engagement in hubspot http://developers.hubspot.com/docs/methods/engagements/delete-engagement
116 117 118 119 |
# File 'lib/hubspot/engagement.rb', line 116 def destroy! Hubspot::Connection.delete_json(ENGAGEMENT_PATH, {engagement_id: id}) @destroyed = true end |
#destroyed? ⇒ Boolean
121 122 123 |
# File 'lib/hubspot/engagement.rb', line 121 def destroyed? !!@destroyed end |
#update!(params) ⇒ Hubspot::Engagement
Updates the properties of an engagement http://developers.hubspot.com/docs/methods/engagements/update_engagement
133 134 135 136 137 138 139 140 141 142 143 |
# File 'lib/hubspot/engagement.rb', line 133 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 |