Module: Contacts

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

Overview

Contacts module

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



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

def all_contacts
  validate_access_token

  response(GET, ALL_CONTACTS)
end

#create_contact(**params) ⇒ Object



13
14
15
16
17
# File 'lib/ruby_hubspot/contacts.rb', line 13

def create_contact(**params)
  validate_access_token

  response(POST, INDIVIDUAL_CONTACT, params)
end

#create_or_update_contact(**params) ⇒ Object



19
20
21
22
23
24
# File 'lib/ruby_hubspot/contacts.rb', line 19

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



41
42
43
44
45
# File 'lib/ruby_hubspot/contacts.rb', line 41

def delete_contact(**params)
  validate_access_token

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

#find_idintificator(params) ⇒ Object



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/ruby_hubspot/contacts.rb', line 47

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



26
27
28
29
30
# File 'lib/ruby_hubspot/contacts.rb', line 26

def show_contact(**params)
  validate_access_token

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

#update_contact(**params) ⇒ Object



32
33
34
35
36
37
38
39
# File 'lib/ruby_hubspot/contacts.rb', line 32

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