Class: Klaviyo::Profiles

Inherits:
Client
  • Object
show all
Defined in:
lib/klaviyo/apis/profiles.rb

Constant Summary collapse

PERSON =
'person'
PEOPLE =
'people'
SEARCH =
'search'

Constants inherited from Client

Client::ALL, Client::BASE_API_URL, Client::CONTENT_JSON, Client::CONTENT_URL_FORM, Client::DEFAULT_COUNT, Client::DEFAULT_PAGE, Client::DEFAULT_SORT_DESC, Client::HTTP_DELETE, Client::HTTP_GET, Client::HTTP_POST, Client::HTTP_PUT, Client::METRIC, Client::METRICS, Client::TIMELINE, Client::V1_API, Client::V2_API

Class Method Summary collapse

Class Method Details

.get_person_attributes(person_id) ⇒ Object

Retrieve all the data attributes for a Klaviyo Person ID.

Parameters:

  • person_id (String)

    the id of the profile

Returns:

  • returns a person object



21
22
23
24
# File 'lib/klaviyo/apis/profiles.rb', line 21

def self.get_person_attributes(person_id)
  path = "#{PERSON}/#{person_id}"
  v1_request(HTTP_GET, path)
end

.get_person_metric_timeline(person_id, metric_id, since: nil, count: DEFAULT_COUNT, sort: DEFAULT_SORT_DESC) ⇒ Object

Listing a person’s event timeline for a particular metric

Parameters:

  • person_id (String)

    the id of the profile

  • metric_id (String)

    the id of the metric

  • since (Integer or String) (defaults to: nil)

    either a Unix timestamp or the UUID from a previous request. Default is the current time.

  • count (Integer) (defaults to: DEFAULT_COUNT)

    number of results to return, default 100

  • sort (String) (defaults to: DEFAULT_SORT_DESC)

    ‘asc’ or ‘desc’, sort order to apply to the timeline. Default is ‘desc’.

Returns:

  • returns a dictionary containing a list of metric event objects



58
59
60
61
62
63
64
65
66
# File 'lib/klaviyo/apis/profiles.rb', line 58

def self.get_person_metric_timeline(person_id, metric_id, since: nil, count: DEFAULT_COUNT, sort: DEFAULT_SORT_DESC)
  path = "#{PERSON}/#{person_id}/#{METRIC}/#{metric_id}/#{TIMELINE}"
  params = {
    :since => since,
    :count => count,
    :sort => sort
  }
  v1_request(HTTP_GET, path, params)
end

.get_person_metrics_timeline(person_id, since: nil, count: DEFAULT_COUNT, sort: DEFAULT_SORT_DESC) ⇒ Object

Listing a person’s event timeline

Parameters:

  • person_id (String)

    the id of the profile

  • since (Integer or String) (defaults to: nil)

    either a Unix timestamp or the UUID from a previous request. Default is the current time.

  • count (Integer) (defaults to: DEFAULT_COUNT)

    number of results to return, default 100

  • sort (String) (defaults to: DEFAULT_SORT_DESC)

    ‘asc’ or ‘desc’, sort order to apply to the timeline. Default is ‘desc’.

Returns:

  • returns a dictionary containing a list of metric event objects



41
42
43
44
45
46
47
48
49
# File 'lib/klaviyo/apis/profiles.rb', line 41

def self.get_person_metrics_timeline(person_id, since: nil, count: DEFAULT_COUNT, sort: DEFAULT_SORT_DESC)
  path = "#{PERSON}/#{person_id}/#{METRICS}/#{TIMELINE}"
  params = {
    :since => since,
    :count => count,
    :sort => sort
  }
  v1_request(HTTP_GET, path, params)
end

.get_profile_id_by_email(email) ⇒ JSON

Retrieves the id of the profile given email

Parameters:

  • email (String)

    the email of the profile

Returns:

  • (JSON)

    a JSON object containing id of the profile



10
11
12
13
14
15
16
# File 'lib/klaviyo/apis/profiles.rb', line 10

def self.get_profile_id_by_email(email)
  path = "#{PEOPLE}/#{SEARCH}"
  params = {
    :email => email
  }
  v2_request(HTTP_GET, path, params)
end

.update_person_attributes(person_id, kwargs = {}) ⇒ Object

Add or update one more more attributes for a Person

Parameters:

  • person_id (String)

    the id of the profile

  • kwargs (Key/value pairs) (defaults to: {})

    attributes to add/update in the profile

Returns:

  • returns the updated person object



30
31
32
33
# File 'lib/klaviyo/apis/profiles.rb', line 30

def self.update_person_attributes(person_id, kwargs = {})
  path = "#{PERSON}/#{person_id}"
  v1_request(HTTP_PUT, path, kwargs)
end