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::KL_USER_AGENT, Client::KL_VERSION, Client::METRIC, Client::METRICS, Client::TIMELINE, Client::V1_API, Client::V2_API

Class Method Summary collapse

Class Method Details

.get_person_attributes(person_id, api_key: nil) ⇒ 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



23
24
25
26
# File 'lib/klaviyo/apis/profiles.rb', line 23

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

.get_person_metric_timeline(person_id, metric_id, since: nil, count: DEFAULT_COUNT, sort: DEFAULT_SORT_DESC, api_key: nil) ⇒ 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



62
63
64
65
66
67
68
69
70
# File 'lib/klaviyo/apis/profiles.rb', line 62

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

.get_person_metrics_timeline(person_id, since: nil, count: DEFAULT_COUNT, sort: DEFAULT_SORT_DESC, api_key: nil) ⇒ 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



44
45
46
47
48
49
50
51
52
# File 'lib/klaviyo/apis/profiles.rb', line 44

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

.get_profile_id_by_email(email, api_key: nil) ⇒ 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



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

def self.get_profile_id_by_email(email, api_key: nil)
  path = "#{PEOPLE}/#{SEARCH}"
  params = {
    :email => email
  }
  v2_request(HTTP_GET, path, api_key: api_key, **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



32
33
34
35
# File 'lib/klaviyo/apis/profiles.rb', line 32

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