Class: HubspotService

Inherits:
Object
  • Object
show all
Defined in:
app/services/hubspot_service.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(contact:) ⇒ HubspotService

Returns a new instance of HubspotService.



6
7
8
# File 'app/services/hubspot_service.rb', line 6

def initialize(contact:)
  @contact = contact.attributes
end

Instance Attribute Details

#contactObject (readonly)

Returns the value of attribute contact.



4
5
6
# File 'app/services/hubspot_service.rb', line 4

def contact
  @contact
end

#pipelineObject (readonly)

Returns the value of attribute pipeline.



4
5
6
# File 'app/services/hubspot_service.rb', line 4

def pipeline
  @pipeline
end

Instance Method Details

#save_lead_infoObject



10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'app/services/hubspot_service.rb', line 10

def save_lead_info
  return if contact_exists?
  hubspot_contact = create_contact
  deal = create_deal
  company = create_company(contact["email"])

  # For type_id values, refer to Hubspot association type definitions
  # https://developers.hubspot.com/docs/api-reference/crm-associations-v4/guide#association-type-id-values
  create_association(from_type: "contacts", to_type: "deals", from_id: hubspot_contact.id, to_id: deal.id, type_id: 4)
  create_association(from_type: "contacts", to_type: "companies", from_id: hubspot_contact.id, to_id: company.id, type_id: 1)
  create_association(from_type: "deals", to_type: "companies", from_id: deal.id, to_id: company.id, type_id: 5)
  create_association(from_type: "deals", to_type: "contacts", from_id: deal.id, to_id: hubspot_contact.id, type_id: 3)
end