lib/hubspot/deal.rb in hubspot-ruby-0.2.1 vs lib/hubspot/deal.rb in hubspot-ruby-0.3.0
- old
+ new
@@ -10,10 +10,11 @@
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'
+ ASSOCIATED_DEAL_PATH = "/deals/v1/deal/associated/:objectType/:objectId"
attr_reader :properties
attr_reader :portal_id
attr_reader :deal_id
attr_reader :company_ids
@@ -58,9 +59,20 @@
# @param count [Integer] the amount of deals to return.
# @param offset [Integer] pages back through recent contacts.
def recent(opts = {})
response = Hubspot::Connection.get_json(RECENT_UPDATED_PATH, opts)
response['results'].map { |d| new(d) }
+ end
+
+ # Find all deals associated to a company
+ # {http://developers.hubspot.com/docs/methods/deals/get-associated-deals}
+ # @param company [Hubspot::Company] the company
+ # @return [Array] Array of Hubspot::Deal records
+ def find_by_company(company)
+ path = ASSOCIATED_DEAL_PATH
+ params = { objectType: :company, objectId: company.vid }
+ response = Hubspot::Connection.get_json(path, params)
+ response["results"].map { |deal_id| find(deal_id) }
end
end
# Archives the contact in hubspot