class Hubspot::Contact

Constants

ALL_PATH
BATCH_UPDATE_PATH
CREATE_OR_UPDATE_PATH
CREATE_PATH
DELETE_PATH
FIND_BY_EMAIL_PATH
FIND_BY_USER_TOKEN_PATH
FIND_PATH
MERGE_PATH
SEARCH_PATH
UPDATE_PATH

Public Class Methods

all(opts = {}) click to toggle source
# File lib/hubspot/contact.rb, line 19
def all(opts = {})
  Hubspot::PagedCollection.new(opts) do |options, offset, limit|
    response = Hubspot::Connection.get_json(
      ALL_PATH,
      options.merge("count" => limit, "vidOffset" => offset)
      )

    contacts = response["contacts"].map { |result| from_result(result) }
    [contacts, response["vid-offset"], response["has-more"]]
  end
end
batch_update(contacts, opts = {}) click to toggle source
# File lib/hubspot/contact.rb, line 76
def batch_update(contacts, opts = {})
  request = contacts.map do |contact|
    # Use the specified options or update with the changes
    changes = opts.empty? ? contact.changes : opts

    unless changes.empty?
      {
        "vid" => contact.id,
        "properties" => changes.map { |k, v| { "property" => k, "value" => v } }
      }
    end
  end

  # Remove any objects without changes and return if there is nothing to update
  request.compact!
  return true if request.empty?

  Hubspot::Connection.post_json(
    BATCH_UPDATE_PATH,
    params: {},
    body: request
  )

  true
end
create(email, properties = {}) click to toggle source
Calls superclass method Hubspot::Resource::create
# File lib/hubspot/contact.rb, line 42
def create(email, properties = {})
  super(properties.merge("email" => email))
end
create_or_update(email, properties = {}) click to toggle source
# File lib/hubspot/contact.rb, line 46
def create_or_update(email, properties = {})
  request = {
    properties: Hubspot::Utils.hash_to_properties(properties.stringify_keys, key_name: "property")
  }
  response = Hubspot::Connection.post_json(CREATE_OR_UPDATE_PATH, params: {email: email}, body: request)
  from_result(response)
end
find_by_email(email) click to toggle source
# File lib/hubspot/contact.rb, line 31
def find_by_email(email)
  response = Hubspot::Connection.get_json(FIND_BY_EMAIL_PATH, email: email)
  from_result(response)
end
find_by_user_token(token) click to toggle source
# File lib/hubspot/contact.rb, line 36
def find_by_user_token(token)
  response = Hubspot::Connection.get_json(FIND_BY_USER_TOKEN_PATH, token: token)
  from_result(response)
end
Also aliased as: find_by_utk
find_by_utk(token)
Alias for: find_by_user_token
merge(primary, secondary) click to toggle source
# File lib/hubspot/contact.rb, line 66
def merge(primary, secondary)
  Hubspot::Connection.post_json(
    MERGE_PATH,
    params: { id: primary.to_i, no_parse: true },
    body: { "vidToMerge" => secondary.to_i }
    )

  true
end

Public Instance Methods

merge(contact) click to toggle source
# File lib/hubspot/contact.rb, line 107
def merge(contact)
  self.class.merge(@id, contact.to_i)
end
name() click to toggle source
# File lib/hubspot/contact.rb, line 103
def name
  [firstname, lastname].compact.join(' ')
end