Class: RecombeeApiClient::MergeUsers

Inherits:
ApiRequest show all
Defined in:
lib/recombee_api_client/api/merge_users.rb

Overview

Merges interactions (purchases, ratings, bookmarks, detail views …) of two different users under a single user ID. This is especially useful for online e-commerce applications working with anonymous users identified by unique tokens such as the session ID. In such applications, it may often happen that a user owns a persistent account, yet accesses the system anonymously while, e.g., putting items into a shopping cart. At some point in time, such as when the user wishes to confirm the purchase, (s)he logs into the system using his/her username and password. The interactions made under anonymous session ID then become connected with the persistent account, and merging these two becomes desirable.

Merging happens between two users referred to as the target and the source. After the merge, all the interactions of the source user are attributed to the target user, and the source user is deleted.

By default, the *Merge Users* request is only available from server-side integrations for security reasons, to prevent potential abuse. If you need to call this request from a client-side environment (such as a web or mobile app), please contact our support and request access to enable this feature for your database.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashNormalizer

#camelize, #normalize_optional

Constructor Details

#initialize(target_user_id, source_user_id, optional = {}) ⇒ MergeUsers

  • *Required arguments*

    • target_user_id -> ID of the target user.

    • source_user_id -> ID of the source user.

  • *Optional arguments (given as hash optional)*

    • cascadeCreate -> Sets whether the user targetUserId should be created if not present in the database.



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/recombee_api_client/api/merge_users.rb', line 31

def initialize(target_user_id, source_user_id, optional = {})
  @target_user_id = target_user_id
  @source_user_id = source_user_id
  optional = normalize_optional(optional)
  @cascade_create = optional['cascadeCreate']
  @optional = optional
  @timeout = 10000
  @ensure_https = false
  @optional.each do |par, _|
    fail UnknownOptionalParameter.new(par) unless ["cascadeCreate"].include? par
  end
end

Instance Attribute Details

#cascade_createObject (readonly)

Returns the value of attribute cascade_create.



19
20
21
# File 'lib/recombee_api_client/api/merge_users.rb', line 19

def cascade_create
  @cascade_create
end

#ensure_httpsObject

Returns the value of attribute ensure_https.



21
22
23
# File 'lib/recombee_api_client/api/merge_users.rb', line 21

def ensure_https
  @ensure_https
end

#source_user_idObject (readonly)

Returns the value of attribute source_user_id.



19
20
21
# File 'lib/recombee_api_client/api/merge_users.rb', line 19

def source_user_id
  @source_user_id
end

#target_user_idObject (readonly)

Returns the value of attribute target_user_id.



19
20
21
# File 'lib/recombee_api_client/api/merge_users.rb', line 19

def target_user_id
  @target_user_id
end

#timeoutObject

Returns the value of attribute timeout.



20
21
22
# File 'lib/recombee_api_client/api/merge_users.rb', line 20

def timeout
  @timeout
end

Instance Method Details

#body_parametersObject

Values of body parameters as a Hash



50
51
52
53
# File 'lib/recombee_api_client/api/merge_users.rb', line 50

def body_parameters
  p = Hash.new
  p
end

#methodObject

HTTP method



45
46
47
# File 'lib/recombee_api_client/api/merge_users.rb', line 45

def method
  :put
end

#pathObject

Relative path to the endpoint



64
65
66
# File 'lib/recombee_api_client/api/merge_users.rb', line 64

def path
  "/{databaseId}/users/#{@target_user_id}/merge/#{@source_user_id}"
end

#query_parametersObject

Values of query parameters as a Hash. name of parameter => value of the parameter



57
58
59
60
61
# File 'lib/recombee_api_client/api/merge_users.rb', line 57

def query_parameters
  params = {}
  params['cascadeCreate'] = @optional['cascadeCreate'] if @optional['cascadeCreate']
  params
end