Module: Contacts

Includes:
Constants
Included in:
Hubspot
Defined in:
lib/ruby_hubspot/contacts.rb

Overview

Companies module adds methods for Contact objects

Constant Summary

Constants included from Constants

Constants::ALL_COMPANIES, Constants::ALL_CONTACTS, Constants::ALL_DEALS, Constants::ALL_SUBMITIONS, Constants::API_URL, Constants::AUTHORIZATION_KEY, Constants::CONTENT_TYPE, Constants::CREATE_OR_UPDATE, Constants::DELETE, Constants::EMAIL, Constants::GET, Constants::INDIVIDUAL_COMPANY, Constants::INDIVIDUAL_CONTACT, Constants::INDIVIDUAL_DEAL, Constants::INDIVIDUAL_SUB, Constants::PATCH, Constants::POST, Constants::PROFILE, Constants::PUT, Constants::VID

Instance Method Summary collapse

Instance Method Details

#all_contactsObject

returns all contacts



8
9
10
11
12
# File 'lib/ruby_hubspot/contacts.rb', line 8

def all_contacts
  validate_access_token

  response(GET, ALL_CONTACTS)
end

#create_contact(**params) ⇒ Object

creates a contact



15
16
17
18
19
# File 'lib/ruby_hubspot/contacts.rb', line 15

def create_contact(**params)
  validate_access_token

  response(POST, INDIVIDUAL_CONTACT, params)
end

#create_or_update_contact(**params) ⇒ Object

creates or updates a contact



22
23
24
25
26
27
# File 'lib/ruby_hubspot/contacts.rb', line 22

def create_or_update_contact(**params)
  validate_access_token
  email_handler(params[:email])

  response(POST, INDIVIDUAL_CONTACT + CREATE_OR_UPDATE + EMAIL + params[:email].to_s, params)
end

#delete_contact(**params) ⇒ Object

deletes a contact



47
48
49
50
51
# File 'lib/ruby_hubspot/contacts.rb', line 47

def delete_contact(**params)
  validate_access_token

  response(DELETE, INDIVIDUAL_CONTACT + find_idintificator(params))
end

#find_idintificator(params) ⇒ Object

checks and finds an idintificator



54
55
56
57
58
59
60
61
62
63
64
# File 'lib/ruby_hubspot/contacts.rb', line 54

def find_idintificator(params)
  identificator_handler(
    %i[email id].any? do |key|
      if params.key?(key)
        identificator_handler(params[key])

        return key == :email ? EMAIL + params[key].to_s : VID + params[key].to_s
      end
    end
  )
end

#show_contact(**params) ⇒ Object

shows a contact



30
31
32
33
34
# File 'lib/ruby_hubspot/contacts.rb', line 30

def show_contact(**params)
  validate_access_token

  response(GET, INDIVIDUAL_CONTACT + find_idintificator(params) + PROFILE)
end

#update_contact(**params) ⇒ Object

updates a contact



37
38
39
40
41
42
43
44
# File 'lib/ruby_hubspot/contacts.rb', line 37

def update_contact(**params)
  validate_access_token

  params_to_update = params.dup
  params_to_update.delete(:id)

  response(POST, INDIVIDUAL_CONTACT + find_idintificator(params) + PROFILE, params_to_update)
end