Class: HubspotClient::Client::Contact

Inherits:
Object
  • Object
show all
Includes:
HTTParty
Defined in:
lib/hubspot_client/client/contact.rb

Constant Summary collapse

BASE_PATH_V3 =
'/crm/v3/objects/contacts'
FIND_PROPERTIES =
%w[firstname lastname email phone lifecyclestage associatedcompanyid].freeze

Instance Method Summary collapse

Instance Method Details

#associate_with(hubspot_id, to_object_type, to_object_type_id, association_type = '1') ⇒ Object

Raises:



48
49
50
51
52
53
54
55
# File 'lib/hubspot_client/client/contact.rb', line 48

def associate_with(hubspot_id, to_object_type, to_object_type_id, association_type = '1')
  path = "#{BASE_PATH_V3}/#{hubspot_id}/associations/#{to_object_type}/#{to_object_type_id}/#{association_type}"
  response = self.class.put(path, headers: headers)

  return response if response.code == 200

  raise AssociationError, response
end

#create(properties) ⇒ Object

Raises:



28
29
30
31
32
33
34
35
36
# File 'lib/hubspot_client/client/contact.rb', line 28

def create(properties)
  response = self.class.post(BASE_PATH_V3,
                             body: { properties: properties }.to_json,
                             headers: headers)

  return response if response.code == 201

  raise ContactNotCreated, response
end

#find_by_email(email) ⇒ Object



17
18
19
20
# File 'lib/hubspot_client/client/contact.rb', line 17

def find_by_email(email)
  query_params = find_query_params({ idProperty: 'email' })
  find_by("#{BASE_PATH_V3}/#{email}?#{query_params}")
end

#find_by_id(hubspot_id) ⇒ Object



22
23
24
25
26
# File 'lib/hubspot_client/client/contact.rb', line 22

def find_by_id(hubspot_id)
  query_params = find_query_params

  find_by("#{BASE_PATH_V3}/#{hubspot_id}?#{query_params}")
end

#update(hubspot_id, properties) ⇒ Object

Raises:



38
39
40
41
42
43
44
45
46
# File 'lib/hubspot_client/client/contact.rb', line 38

def update(hubspot_id, properties)
  response = self.class.patch("#{BASE_PATH_V3}/#{hubspot_id}",
                              body: { properties: properties }.to_json,
                              headers: headers)

  return response if response.code == 200

  raise ContactNotUpdated, response
end