lib/hubspot/deal.rb in hubspot-ruby-0.2.0 vs lib/hubspot/deal.rb in hubspot-ruby-0.2.1
- old
+ new
@@ -9,10 +9,11 @@
class Deal
CREATE_DEAL_PATH = "/deals/v1/deal"
DEAL_PATH = "/deals/v1/deal/:deal_id"
RECENT_UPDATED_PATH = "/deals/v1/deal/recent/modified"
UPDATE_DEAL_PATH = '/deals/v1/deal/:deal_id'
+ ASSOCIATE_DEAL_PATH = '/deals/v1/deal/:deal_id/associations/:OBJECTTYPE?id=:objectId'
attr_reader :properties
attr_reader :portal_id
attr_reader :deal_id
attr_reader :company_ids
@@ -33,9 +34,20 @@
post_data = associations_hash.merge({ properties: Hubspot::Utils.hash_to_properties(params, key_name: "name") })
response = Hubspot::Connection.post_json(CREATE_DEAL_PATH, params: {}, body: post_data )
new(response)
end
+
+ # Associate a deal with a contact or company
+ # {http://developers.hubspot.com/docs/methods/deals/associate_deal}
+ # Usage
+ # Hubspot::Deal.associate!(45146940, [], [52])
+ def associate!(deal_id, company_ids=[], vids=[])
+ objecttype = company_ids.any? ? 'COMPANY' : 'CONTACT'
+ object_ids = (company_ids.any? ? company_ids : vids).join('&id=')
+ Hubspot::Connection.put_json(ASSOCIATE_DEAL_PATH, params: { deal_id: deal_id, OBJECTTYPE: objecttype, objectId: object_ids}, body: {})
+ end
+
def find(deal_id)
response = Hubspot::Connection.get_json(DEAL_PATH, { deal_id: deal_id })
new(response)
end