Class: RecombeeApiClient::AddUserProperty

Inherits:
ApiRequest
  • Object
show all
Defined in:
lib/recombee_api_client/api/add_user_property.rb

Overview

Adding a user property is somewhat equivalent to adding a column to the table of users. The users may be characterized by various properties of different types.

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from HashNormalizer

#camelize, #normalize_hash_to_camel_case

Constructor Details

#initialize(property_name, type, optional = {}) ⇒ AddUserProperty

  • Required arguments

    • property_name -> Name of the user property to be created. Currently, the following names are reserved: id, userid, case-insensitively. Also, the length of the property name must not exceed 63 characters.

    • type -> Value type of the user property to be created. One of: int, double, string, boolean, timestamp, set.

  • int - Signed integer number.

  • double - Floating point number. It uses 64-bit base-2 format (IEEE 754 standard).

  • string - UTF-8 string.

  • boolean - true / false

  • timestamp - Value representing date and time. ISO8601-1 pattern (string) or UTC epoch time (number).

  • set - Set of strings.

  • Optional arguments (given as hash optional)

    • role -> Role to assign to the property.

    • metadata -> List of metadata entries to assign to the property.



40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/recombee_api_client/api/add_user_property.rb', line 40

def initialize(property_name, type, optional = {})
  @property_name = property_name
  @type = type
  optional = normalize_hash_to_camel_case(optional)
  @role = optional['role']
  @metadata = optional['metadata']
  @optional = optional
  @timeout = 100_000
  @ensure_https = false
  @optional.each do |par, _|
    raise UnknownOptionalParameter.new(par) unless %w[role metadata].include? par
  end
end

Instance Attribute Details

#ensure_https ⇒ Object

Returns the value of attribute ensure_https.



14
15
16
# File 'lib/recombee_api_client/api/add_user_property.rb', line 14

def ensure_https
  @ensure_https
end

#metadata ⇒ Object (readonly)

Returns the value of attribute metadata.



13
14
15
# File 'lib/recombee_api_client/api/add_user_property.rb', line 13

def 
  @metadata
end

#property_name ⇒ Object (readonly)

Returns the value of attribute property_name.



13
14
15
# File 'lib/recombee_api_client/api/add_user_property.rb', line 13

def property_name
  @property_name
end

#role ⇒ Object (readonly)

Returns the value of attribute role.



13
14
15
# File 'lib/recombee_api_client/api/add_user_property.rb', line 13

def role
  @role
end

#timeout ⇒ Object

Returns the value of attribute timeout.



14
15
16
# File 'lib/recombee_api_client/api/add_user_property.rb', line 14

def timeout
  @timeout
end

#type ⇒ Object (readonly)

Returns the value of attribute type.



13
14
15
# File 'lib/recombee_api_client/api/add_user_property.rb', line 13

def type
  @type
end

Instance Method Details

#body_parameters ⇒ Object

Values of body parameters as a Hash



60
61
62
63
64
65
66
67
# File 'lib/recombee_api_client/api/add_user_property.rb', line 60

def body_parameters
  p = {}
  p['type'] = @type
  p['role'] = @optional['role'] if @optional.include? 'role'
  p['metadata'] = @optional['metadata'] if @optional.include? 'metadata'

  p
end

#method ⇒ Object

HTTP method



55
56
57
# File 'lib/recombee_api_client/api/add_user_property.rb', line 55

def method
  :put
end

#path ⇒ Object

Relative path to the endpoint



76
77
78
# File 'lib/recombee_api_client/api/add_user_property.rb', line 76

def path
  "/{databaseId}/users/properties/#{@property_name}"
end

#query_parameters ⇒ Object

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



71
72
73
# File 'lib/recombee_api_client/api/add_user_property.rb', line 71

def query_parameters
  {}
end