From 9f29322dfe59f7532331263712f56b4b8560bb93 Mon Sep 17 00:00:00 2001 From: Yannick Fonjallaz Date: Thu, 21 Nov 2019 14:01:47 +0100 Subject: [PATCH] Deal.find_by_association uses Association --- lib/hubspot/deal.rb | 18 +- ..._find_by_company_returns_company_deals.yml | 239 +++++++++++++++++ ..._find_by_contact_returns_contact_deals.yml | 242 ++++++++++++++++++ .../vcr_cassettes/deal_find_by_company.yml | 136 ---------- spec/lib/hubspot/deal_spec.rb | 18 +- 5 files changed, 502 insertions(+), 151 deletions(-) create mode 100644 spec/fixtures/vcr_cassettes/Hubspot_Deal_find_by_company_returns_company_deals.yml create mode 100644 spec/fixtures/vcr_cassettes/Hubspot_Deal_find_by_contact_returns_contact_deals.yml delete mode 100644 spec/fixtures/vcr_cassettes/deal_find_by_company.yml diff --git a/lib/hubspot/deal.rb b/lib/hubspot/deal.rb index 0e9d6aec..d1bd763c 100644 --- a/lib/hubspot/deal.rb +++ b/lib/hubspot/deal.rb @@ -12,7 +12,6 @@ class Deal DEAL_PATH = "/deals/v1/deal/:deal_id" RECENT_UPDATED_PATH = "/deals/v1/deal/recent/modified" UPDATE_DEAL_PATH = '/deals/v1/deal/:deal_id' - ASSOCIATED_DEAL_PATH = "/deals/v1/deal/associated/:objectType/:objectId" attr_reader :properties attr_reader :portal_id @@ -96,20 +95,15 @@ def find_by_contact(contact) end # Find all deals associated to a contact or company - # {http://developers.hubspot.com/docs/methods/deals/get-associated-deals} # @param object [Hubspot::Contact || Hubspot::Company] a contact or company # @return [Array] Array of Hubspot::Deal records def find_by_association(object) - path = ASSOCIATED_DEAL_PATH - objectType = case object - when Hubspot::Company then :company - when Hubspot::Contact then :contact - else raise(Hubspot::InvalidParams, "Instance type not supported") - end - - params = { objectType: objectType, objectId: object.id } - response = Hubspot::Connection.get_json(path, params) - response["results"].map { |deal_id| find(deal_id) } + definition = case object + when Hubspot::Company then Hubspot::Association::COMPANY_TO_DEAL + when Hubspot::Contact then Hubspot::Association::CONTACT_TO_DEAL + else raise(Hubspot::InvalidParams, 'Instance type not supported') + end + Hubspot::Association.all(object.id, definition) end end diff --git a/spec/fixtures/vcr_cassettes/Hubspot_Deal_find_by_company_returns_company_deals.yml b/spec/fixtures/vcr_cassettes/Hubspot_Deal_find_by_company_returns_company_deals.yml new file mode 100644 index 00000000..10a96c4f --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Hubspot_Deal_find_by_company_returns_company_deals.yml @@ -0,0 +1,239 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.hubapi.com/companies/v2/companies/?hapikey=demo + body: + encoding: UTF-8 + string: '{"properties":[{"name":"name","value":"Wunsch-Keebler"},{"name":"domain","value":"pouroscasper.com"}]}' + headers: + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 21 Nov 2019 12:57:55 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 21-Dec-19 + 12:57:54 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249795' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '99' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 5392d5059bc8edc7-CDG + body: + encoding: UTF-8 + string: '{"portalId":62515,"companyId":2613286304,"isDeleted":false,"properties":{"website":{"value":"pouroscasper.com","timestamp":1574341074897,"source":"CALCULATED","sourceId":null,"versions":[{"name":"website","value":"pouroscasper.com","timestamp":1574341074897,"source":"CALCULATED","sourceVid":[],"requestId":"d0cd4893-cca7-41c2-a29a-5ad819287f92"}]},"hs_lastmodifieddate":{"value":"1574341074897","timestamp":1574341074897,"source":"CALCULATED","sourceId":"d0cd4893-cca7-41c2-a29a-5ad819287f92","versions":[{"name":"hs_lastmodifieddate","value":"1574341074897","timestamp":1574341074897,"sourceId":"d0cd4893-cca7-41c2-a29a-5ad819287f92","source":"CALCULATED","sourceVid":[],"requestId":"d0cd4893-cca7-41c2-a29a-5ad819287f92"}]},"domain":{"value":"pouroscasper.com","timestamp":1574341074897,"source":"API","sourceId":"d0cd4893-cca7-41c2-a29a-5ad819287f92","versions":[{"name":"domain","value":"pouroscasper.com","timestamp":1574341074897,"sourceId":"d0cd4893-cca7-41c2-a29a-5ad819287f92","source":"API","sourceVid":[],"requestId":"d0cd4893-cca7-41c2-a29a-5ad819287f92"}]},"hs_object_id":{"value":"2613286304","timestamp":1574341074897,"source":"API","sourceId":"d0cd4893-cca7-41c2-a29a-5ad819287f92","versions":[{"name":"hs_object_id","value":"2613286304","timestamp":1574341074897,"sourceId":"d0cd4893-cca7-41c2-a29a-5ad819287f92","source":"API","sourceVid":[],"requestId":"d0cd4893-cca7-41c2-a29a-5ad819287f92"}]},"name":{"value":"Wunsch-Keebler","timestamp":1574341074897,"source":"API","sourceId":"d0cd4893-cca7-41c2-a29a-5ad819287f92","versions":[{"name":"name","value":"Wunsch-Keebler","timestamp":1574341074897,"sourceId":"d0cd4893-cca7-41c2-a29a-5ad819287f92","source":"API","sourceVid":[],"requestId":"d0cd4893-cca7-41c2-a29a-5ad819287f92"}]},"createdate":{"value":"1574341074897","timestamp":1574341074897,"source":"API","sourceId":"d0cd4893-cca7-41c2-a29a-5ad819287f92","versions":[{"name":"createdate","value":"1574341074897","timestamp":1574341074897,"sourceId":"d0cd4893-cca7-41c2-a29a-5ad819287f92","source":"API","sourceVid":[],"requestId":"d0cd4893-cca7-41c2-a29a-5ad819287f92"}]}},"additionalDomains":[],"stateChanges":[],"mergeAudits":[]}' + http_version: + recorded_at: Thu, 21 Nov 2019 12:57:55 GMT +- request: + method: post + uri: https://api.hubapi.com/deals/v1/deal?hapikey=demo + body: + encoding: UTF-8 + string: '{"portalId":62515,"associations":{"associatedCompanyIds":[2613286304],"associatedVids":[]},"properties":[{"name":"amount","value":"30"}]}' + headers: + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 21 Nov 2019 12:57:55 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 21-Dec-19 + 12:57:55 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249794' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '98' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 5392d5085d8c3bcd-CDG + body: + encoding: UTF-8 + string: '{"portalId":62515,"dealId":1191512073,"isDeleted":false,"associations":{"associatedVids":[],"associatedCompanyIds":[2613286304],"associatedDealIds":[],"associatedTicketIds":[]},"properties":{"hs_closed_amount_in_home_currency":{"value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount_in_home_currency","value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount":{"value":"30","timestamp":1574341075347,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1574341075347,"source":"API","sourceVid":[]}]},"hs_closed_amount":{"value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount","value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_lastmodifieddate":{"value":"1574341075347","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1574341075347","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1574341075347","timestamp":1574341075347,"source":"API","sourceId":"","versions":[{"name":"hs_createdate","value":"1574341075347","timestamp":1574341075347,"sourceId":"","source":"API","sourceVid":[]}]},"hs_object_id":{"value":"1191512073","timestamp":1574341075347,"source":"API","sourceId":null,"versions":[{"name":"hs_object_id","value":"1191512073","timestamp":1574341075347,"source":"API","sourceVid":[]}]},"createdate":{"value":"1574341075347","timestamp":1574341075347,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1574341075347","timestamp":1574341075347,"source":"API","sourceVid":[]}]},"hs_projected_amount":{"value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount","value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount_in_home_currency":{"value":"30","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"amount_in_home_currency","value":"30","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_deal_stage_probability":{"value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_deal_stage_probability","value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"days_to_close":{"value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"days_to_close","value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_projected_amount_in_home_currency":{"value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount_in_home_currency","value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]}},"imports":[],"stateChanges":[]}' + http_version: + recorded_at: Thu, 21 Nov 2019 12:57:55 GMT +- request: + method: get + uri: https://api.hubapi.com/crm-associations/v1/associations/2613286304/HUBSPOT_DEFINED/6?hapikey=demo&limit=25&offset= + body: + encoding: US-ASCII + string: '' + headers: {} + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 21 Nov 2019 12:57:55 GMT + Content-Type: + - application/json;charset=utf-8 + Content-Length: + - '60' + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 21-Dec-19 + 12:57:55 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249793' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '97' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 5392d50a9e74ee3b-CDG + body: + encoding: UTF-8 + string: '{"results":[1191512073],"hasMore":false,"offset":1191512073}' + http_version: + recorded_at: Thu, 21 Nov 2019 12:57:55 GMT +- request: + method: get + uri: https://api.hubapi.com/deals/v1/deal/1191512073?hapikey=demo + body: + encoding: US-ASCII + string: '' + headers: {} + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 21 Nov 2019 12:57:56 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 21-Dec-19 + 12:57:55 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249792' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '96' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 5392d50cafd2a879-CDG + body: + encoding: UTF-8 + string: '{"portalId":62515,"dealId":1191512073,"isDeleted":false,"associations":{"associatedVids":[],"associatedCompanyIds":[2613286304],"associatedDealIds":[],"associatedTicketIds":[]},"properties":{"hs_closed_amount_in_home_currency":{"value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount_in_home_currency","value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount":{"value":"30","timestamp":1574341075347,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1574341075347,"source":"API","sourceVid":[]}]},"num_associated_contacts":{"value":"0","timestamp":1574341075849,"source":"CALCULATED","sourceId":"RollupProperties","versions":[{"name":"num_associated_contacts","value":"0","timestamp":1574341075849,"sourceId":"RollupProperties","source":"CALCULATED","sourceVid":[]}]},"createdate":{"value":"1574341075347","timestamp":1574341075347,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1574341075347","timestamp":1574341075347,"source":"API","sourceVid":[]}]},"amount_in_home_currency":{"value":"30","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"amount_in_home_currency","value":"30","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_deal_stage_probability":{"value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_deal_stage_probability","value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"days_to_close":{"value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"days_to_close","value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_closed_amount":{"value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount","value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_lastmodifieddate":{"value":"1574341075880","timestamp":1574341075880,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1574341075880","timestamp":1574341075880,"source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1574341075347","timestamp":1574341075347,"source":"API","sourceId":"","versions":[{"name":"hs_createdate","value":"1574341075347","timestamp":1574341075347,"sourceId":"","source":"API","sourceVid":[]}]},"hs_object_id":{"value":"1191512073","timestamp":1574341075347,"source":"API","sourceId":null,"versions":[{"name":"hs_object_id","value":"1191512073","timestamp":1574341075347,"source":"API","sourceVid":[]}]},"hs_projected_amount":{"value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount","value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_projected_amount_in_home_currency":{"value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount_in_home_currency","value":"0","timestamp":1574341075347,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]}},"imports":[],"stateChanges":[]}' + http_version: + recorded_at: Thu, 21 Nov 2019 12:57:56 GMT +recorded_with: VCR 5.0.0 diff --git a/spec/fixtures/vcr_cassettes/Hubspot_Deal_find_by_contact_returns_contact_deals.yml b/spec/fixtures/vcr_cassettes/Hubspot_Deal_find_by_contact_returns_contact_deals.yml new file mode 100644 index 00000000..8fd5e5a4 --- /dev/null +++ b/spec/fixtures/vcr_cassettes/Hubspot_Deal_find_by_contact_returns_contact_deals.yml @@ -0,0 +1,242 @@ +--- +http_interactions: +- request: + method: post + uri: https://api.hubapi.com/contacts/v1/contact?hapikey=demo + body: + encoding: UTF-8 + string: '{"properties":[{"property":"firstname","value":"Maris"},{"property":"lastname","value":"Littel"},{"property":"email","value":"chae@example.org"}]}' + headers: + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 21 Nov 2019 12:57:56 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 21-Dec-19 + 12:57:56 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249791' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '95' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 5392d50e7ba93bc7-CDG + body: + encoding: UTF-8 + string: '{"vid":74701,"canonical-vid":74701,"merged-vids":[],"portal-id":62515,"is-contact":true,"profile-token":"AO_T-mPIsRE00kPhf6nVL_fVjlPJZk4_QnOQLBl_IOv7oJqSyOQ_uR_lIXxEOcxHT-mb2hbnoqdofwrfhMJibb6ZK97PGQP4w2BiQULtebDgaLrG1KZr7XmGNu2rJemUPaA8N_Bktze7","profile-url":"https://app.hubspot.com/contacts/62515/contact/74701","properties":{"firstname":{"value":"Maris","versions":[{"value":"Maris","source-type":"API","source-id":null,"source-label":null,"timestamp":1574341076306,"selected":false}]},"email":{"value":"chae@example.org","versions":[{"value":"chae@example.org","source-type":"API","source-id":null,"source-label":null,"timestamp":1574341076306,"selected":false}]},"lastname":{"value":"Littel","versions":[{"value":"Littel","source-type":"API","source-id":null,"source-label":null,"timestamp":1574341076306,"selected":false}]}},"form-submissions":[],"list-memberships":[],"identity-profiles":[{"vid":74701,"is-deleted":false,"is-contact":false,"pointer-vid":0,"previous-vid":0,"linked-vids":[],"saved-at-timestamp":0,"deleted-changed-timestamp":0,"identities":[{"type":"EMAIL","value":"chae@example.org","timestamp":1574341076314,"is-primary":true,"source":"UNSPECIFIED"},{"type":"LEAD_GUID","value":"fcb9f4ec-a1be-4a3b-b933-e05f3cc1b31e","timestamp":1574341076334,"source":"UNSPECIFIED"}]}],"merge-audits":[]}' + http_version: + recorded_at: Thu, 21 Nov 2019 12:57:56 GMT +- request: + method: post + uri: https://api.hubapi.com/deals/v1/deal?hapikey=demo + body: + encoding: UTF-8 + string: '{"portalId":62515,"associations":{"associatedCompanyIds":[],"associatedVids":[74701]},"properties":[{"name":"amount","value":"30"}]}' + headers: + Content-Type: + - application/json + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 21 Nov 2019 12:57:56 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 21-Dec-19 + 12:57:56 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249790' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '94' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 5392d5119d2bb7a5-CDG + body: + encoding: UTF-8 + string: '{"portalId":62515,"dealId":1191499667,"isDeleted":false,"associations":{"associatedVids":[74701],"associatedCompanyIds":[],"associatedDealIds":[],"associatedTicketIds":[]},"properties":{"hs_closed_amount_in_home_currency":{"value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount_in_home_currency","value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount":{"value":"30","timestamp":1574341076810,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1574341076810,"source":"API","sourceVid":[]}]},"hs_closed_amount":{"value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount","value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_lastmodifieddate":{"value":"1574341076810","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1574341076810","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1574341076810","timestamp":1574341076810,"source":"API","sourceId":"","versions":[{"name":"hs_createdate","value":"1574341076810","timestamp":1574341076810,"sourceId":"","source":"API","sourceVid":[]}]},"hs_object_id":{"value":"1191499667","timestamp":1574341076810,"source":"API","sourceId":null,"versions":[{"name":"hs_object_id","value":"1191499667","timestamp":1574341076810,"source":"API","sourceVid":[]}]},"createdate":{"value":"1574341076810","timestamp":1574341076810,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1574341076810","timestamp":1574341076810,"source":"API","sourceVid":[]}]},"hs_projected_amount":{"value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount","value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount_in_home_currency":{"value":"30","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"amount_in_home_currency","value":"30","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"days_to_close":{"value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"days_to_close","value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_deal_stage_probability":{"value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_deal_stage_probability","value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_projected_amount_in_home_currency":{"value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount_in_home_currency","value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]}},"imports":[],"stateChanges":[]}' + http_version: + recorded_at: Thu, 21 Nov 2019 12:57:56 GMT +- request: + method: get + uri: https://api.hubapi.com/crm-associations/v1/associations/74701/HUBSPOT_DEFINED/4?hapikey=demo&limit=25&offset= + body: + encoding: US-ASCII + string: '' + headers: {} + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 21 Nov 2019 12:57:57 GMT + Content-Type: + - application/json;charset=utf-8 + Content-Length: + - '60' + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 21-Dec-19 + 12:57:56 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249789' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '93' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Accept-Ranges: + - bytes + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 5392d5131880edb3-CDG + body: + encoding: UTF-8 + string: '{"results":[1191499667],"hasMore":false,"offset":1191499667}' + http_version: + recorded_at: Thu, 21 Nov 2019 12:57:57 GMT +- request: + method: get + uri: https://api.hubapi.com/deals/v1/deal/1191499667?hapikey=demo + body: + encoding: US-ASCII + string: '' + headers: {} + response: + status: + code: 200 + message: OK + headers: + Date: + - Thu, 21 Nov 2019 12:57:57 GMT + Content-Type: + - application/json;charset=utf-8 + Transfer-Encoding: + - chunked + Connection: + - keep-alive + Set-Cookie: + - __cfduid=redacted; expires=Sat, 21-Dec-19 + 12:57:57 GMT; path=/; domain=.hubapi.com; HttpOnly + X-Trace: + - redacted + X-Hubspot-Ratelimit-Daily: + - '250000' + X-Hubspot-Ratelimit-Daily-Remaining: + - '249788' + X-Hubspot-Ratelimit-Interval-Milliseconds: + - '10000' + X-Hubspot-Ratelimit-Remaining: + - '92' + X-Hubspot-Ratelimit-Max: + - '100' + X-Hubspot-Ratelimit-Secondly: + - '10' + X-Hubspot-Ratelimit-Secondly-Remaining: + - '9' + Vary: + - Accept-Encoding + Access-Control-Allow-Credentials: + - 'false' + Cf-Cache-Status: + - DYNAMIC + Strict-Transport-Security: + - max-age=31536000; includeSubDomains; preload + Expect-Ct: + - max-age=604800, report-uri="https://report-uri.cloudflare.com/cdn-cgi/beacon/expect-ct" + Server: + - cloudflare + Cf-Ray: + - 5392d5147ee5bd72-CDG + body: + encoding: UTF-8 + string: '{"portalId":62515,"dealId":1191499667,"isDeleted":false,"associations":{"associatedVids":[74701],"associatedCompanyIds":[],"associatedDealIds":[],"associatedTicketIds":[]},"properties":{"hs_closed_amount_in_home_currency":{"value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount_in_home_currency","value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount":{"value":"30","timestamp":1574341076810,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1574341076810,"source":"API","sourceVid":[]}]},"hs_closed_amount":{"value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_closed_amount","value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_lastmodifieddate":{"value":"1574341076810","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1574341076810","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1574341076810","timestamp":1574341076810,"source":"API","sourceId":"","versions":[{"name":"hs_createdate","value":"1574341076810","timestamp":1574341076810,"sourceId":"","source":"API","sourceVid":[]}]},"hs_object_id":{"value":"1191499667","timestamp":1574341076810,"source":"API","sourceId":null,"versions":[{"name":"hs_object_id","value":"1191499667","timestamp":1574341076810,"source":"API","sourceVid":[]}]},"createdate":{"value":"1574341076810","timestamp":1574341076810,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1574341076810","timestamp":1574341076810,"source":"API","sourceVid":[]}]},"hs_projected_amount":{"value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount","value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"amount_in_home_currency":{"value":"30","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"amount_in_home_currency","value":"30","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_deal_stage_probability":{"value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_deal_stage_probability","value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"days_to_close":{"value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"days_to_close","value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]},"hs_projected_amount_in_home_currency":{"value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_projected_amount_in_home_currency","value":"0","timestamp":1574341076810,"source":"CALCULATED","sourceVid":[],"sourceMetadata":""}]}},"imports":[],"stateChanges":[]}' + http_version: + recorded_at: Thu, 21 Nov 2019 12:57:57 GMT +recorded_with: VCR 5.0.0 diff --git a/spec/fixtures/vcr_cassettes/deal_find_by_company.yml b/spec/fixtures/vcr_cassettes/deal_find_by_company.yml deleted file mode 100644 index cf7d5808..00000000 --- a/spec/fixtures/vcr_cassettes/deal_find_by_company.yml +++ /dev/null @@ -1,136 +0,0 @@ ---- -http_interactions: -- request: - method: post - uri: https://api.hubapi.com/companies/v2/companies/?hapikey=demo - body: - encoding: UTF-8 - string: '{"properties":[{"name":"name","value":"Test Company"}]}' - headers: - Content-Type: - - application/json - response: - status: - code: 200 - message: OK - headers: - Access-Control-Allow-Credentials: - - 'false' - Content-Type: - - application/json; charset=UTF-8 - Content-Length: - - '800' - Date: - - Thu, 02 Nov 2017 00:39:01 GMT - Connection: - - keep-alive - body: - encoding: UTF-8 - string: '{"portalId":62515,"companyId":592416090,"isDeleted":false,"properties":{"hs_lastmodifieddate":{"value":"1509583141275","timestamp":1509583141275,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1509583141275","timestamp":1509583141275,"source":"CALCULATED","sourceVid":[]}]},"name":{"value":"Test - Company","timestamp":1509583141275,"source":"API","sourceId":null,"versions":[{"name":"name","value":"Test - Company","timestamp":1509583141275,"source":"API","sourceVid":[]}]},"createdate":{"value":"1509583141275","timestamp":1509583141275,"source":"API","sourceId":"API","versions":[{"name":"createdate","value":"1509583141275","timestamp":1509583141275,"sourceId":"API","source":"API","sourceVid":[]}]}},"additionalDomains":[],"stateChanges":[],"mergeAudits":[]}' - http_version: - recorded_at: Thu, 02 Nov 2017 00:39:01 GMT -- request: - method: post - uri: https://api.hubapi.com/deals/v1/deal?hapikey=demo - body: - encoding: UTF-8 - string: '{"portalId":62515,"associations":{"associatedCompanyIds":[592416090],"associatedVids":[27136]},"properties":[{"name":"amount","value":"30"}]}' - headers: - Content-Type: - - application/json - response: - status: - code: 200 - message: OK - headers: - Access-Control-Allow-Credentials: - - 'false' - Content-Type: - - application/json; charset=UTF-8 - Content-Length: - - '1328' - Date: - - Thu, 02 Nov 2017 00:39:01 GMT - Connection: - - keep-alive - body: - encoding: UTF-8 - string: '{"portalId":62515,"dealId":213404277,"isDeleted":false,"associations":{"associatedVids":[],"associatedCompanyIds":[592416090],"associatedDealIds":[]},"associationCreateFailures":[{"association":{"fromObjectId":27136,"associationType":"CONTACT_TO_DEAL","toObjectId":213404277,"associationCategory":"HUBSPOT_DEFINED","associationTypeId":4,"timestamp":null},"failReason":"INVALID_OBJECT_IDS","message":"CONTACT=27136 - is not valid"}],"properties":{"amount":{"value":"30","timestamp":1509583141407,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1509583141407,"source":"API","sourceVid":[]}]},"hs_lastmodifieddate":{"value":"1509583141407","timestamp":1509583141407,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1509583141407","timestamp":1509583141407,"source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1509583141407","timestamp":1509583141407,"source":"API","sourceId":null,"versions":[{"name":"hs_createdate","value":"1509583141407","timestamp":1509583141407,"source":"API","sourceVid":[]}]},"createdate":{"value":"1509583141407","timestamp":1509583141407,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1509583141407","timestamp":1509583141407,"source":"API","sourceVid":[]}]}},"imports":[],"stateChanges":[]}' - http_version: - recorded_at: Thu, 02 Nov 2017 00:39:01 GMT -- request: - method: get - uri: https://api.hubapi.com/deals/v1/deal/associated/company/592416090?hapikey=demo - body: - encoding: US-ASCII - string: '' - headers: - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - Accept: - - "*/*" - User-Agent: - - Ruby - response: - status: - code: 200 - message: OK - headers: - Access-Control-Allow-Credentials: - - 'false' - Content-Type: - - application/json; charset=UTF-8 - Vary: - - Accept-Encoding - - user-agent - Date: - - Thu, 02 Nov 2017 00:39:01 GMT - Content-Length: - - '58' - Connection: - - keep-alive - body: - encoding: UTF-8 - string: '{"results":[213404277],"hasMore":false,"offset":213404277}' - http_version: - recorded_at: Thu, 02 Nov 2017 00:39:01 GMT -- request: - method: get - uri: https://api.hubapi.com/deals/v1/deal/213404277?hapikey=demo - body: - encoding: US-ASCII - string: '' - headers: - Accept-Encoding: - - gzip;q=1.0,deflate;q=0.6,identity;q=0.3 - Accept: - - "*/*" - User-Agent: - - Ruby - response: - status: - code: 200 - message: OK - headers: - Access-Control-Allow-Credentials: - - 'false' - Content-Type: - - application/json; charset=UTF-8 - Vary: - - Accept-Encoding - - user-agent - Date: - - Thu, 02 Nov 2017 00:39:01 GMT - Content-Length: - - '1237' - Connection: - - keep-alive - body: - encoding: UTF-8 - string: '{"portalId":62515,"dealId":213404277,"isDeleted":false,"associations":{"associatedVids":[],"associatedCompanyIds":[592416090],"associatedDealIds":[]},"properties":{"amount":{"value":"30","timestamp":1509583141407,"source":"API","sourceId":null,"versions":[{"name":"amount","value":"30","timestamp":1509583141407,"source":"API","sourceVid":[]}]},"hs_lastmodifieddate":{"value":"1509583141407","timestamp":1509583141407,"source":"CALCULATED","sourceId":null,"versions":[{"name":"hs_lastmodifieddate","value":"1509583141407","timestamp":1509583141407,"source":"CALCULATED","sourceVid":[]}]},"num_associated_contacts":{"value":"0","timestamp":0,"source":"CALCULATED","sourceId":null,"versions":[{"name":"num_associated_contacts","value":"0","source":"CALCULATED","sourceVid":[]}]},"hs_createdate":{"value":"1509583141407","timestamp":1509583141407,"source":"API","sourceId":null,"versions":[{"name":"hs_createdate","value":"1509583141407","timestamp":1509583141407,"source":"API","sourceVid":[]}]},"createdate":{"value":"1509583141407","timestamp":1509583141407,"source":"API","sourceId":null,"versions":[{"name":"createdate","value":"1509583141407","timestamp":1509583141407,"source":"API","sourceVid":[]}]}},"imports":[],"stateChanges":[]}' - http_version: - recorded_at: Thu, 02 Nov 2017 00:39:01 GMT -recorded_with: VCR 3.0.3 diff --git a/spec/lib/hubspot/deal_spec.rb b/spec/lib/hubspot/deal_spec.rb index b6cb325b..444aa611 100644 --- a/spec/lib/hubspot/deal_spec.rb +++ b/spec/lib/hubspot/deal_spec.rb @@ -68,9 +68,9 @@ end describe '.find_by_company' do - cassette 'deal_find_by_company' - let(:company) { Hubspot::Company.create(name: 'Test Company') } - let(:deal) { Hubspot::Deal.create!(portal_id, [company.id], [vid], { amount: amount }) } + cassette + let(:company) { create :company } + let!(:deal) { Hubspot::Deal.create!(portal_id, [company.id], [], { amount: amount }) } it 'returns company deals' do deals = Hubspot::Deal.find_by_company(company) @@ -79,6 +79,18 @@ end end + describe '.find_by_contact' do + cassette + let(:contact) { create :contact } + let!(:deal) { Hubspot::Deal.create!(portal_id, [], [contact.id], { amount: amount }) } + + it 'returns contact deals' do + deals = Hubspot::Deal.find_by_contact(contact) + deals.first.deal_id.should eql deal.deal_id + deals.first.properties['amount'].should eql amount + end + end + describe '.recent' do cassette 'find_all_recent_updated_deals'