Class: Followanalytics::Attributes::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/followanalytics/attributes.rb

Constant Summary collapse

MISSING_SOR =
'Missing System of Record identifier.'.freeze
MISSING_API_KEY =
'Missing api key in configuration.'.freeze
PREDEFINED_ATTRIBUTE_KEYS =
%w(
  first_name last_name email date_of_birth gender country city region
  profile_picture
).freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(sor_identifier) ⇒ Client

Initializes the Attributes client.

Raises:



23
24
25
26
# File 'lib/followanalytics/attributes.rb', line 23

def initialize(sor_identifier)
  raise Followanalytics::Error, MISSING_SOR if sor_identifier.nil?
  @sor_identifier = sor_identifier
end

Instance Attribute Details

#sor_identifierObject

Returns the value of attribute sor_identifier.



7
8
9
# File 'lib/followanalytics/attributes.rb', line 7

def sor_identifier
  @sor_identifier
end

Instance Method Details

#add_set_value(value, key, customer_id) ⇒ Object

Add a value to an attribute of type set.

Examples:

Add the value “strawberry” to the set attribute with the key “fruit_salad” for the customer “tim”

client.add_set_value("strawberry", "fruit_salad", "tim")


68
69
70
71
72
73
# File 'lib/followanalytics/attributes.rb', line 68

def add_set_value(value, key, customer_id)
  hash = attribute_hash(value, key, customer_id).tap do |hsh|
    hsh['action_type'] = 'ADD'
  end
  send_attributes(hash)
end

#remove_set_value(value, key, customer_id) ⇒ Object

Remove a value to an attribute of type set.

Examples:

Remove the value “strawberry” to the set attribute with the key “fruit_salad” for the customer “tim”

client.remove_set_value("strawberry", "fruit_salad", "tim")


83
84
85
86
87
88
# File 'lib/followanalytics/attributes.rb', line 83

def remove_set_value(value, key, customer_id)
  hash = attribute_hash(value, key, customer_id).tap do |hsh|
    hsh['action_type'] = 'REMOVE'
  end
  send_attributes(hash)
end

#set_value(value, key, customer_id) ⇒ Object

Set one value for a customer.

Examples:

Set the value “apple” to the attribute with the key “favorite_fruit” for the customer “tim”

client.set_value("apple", "favorite_fruit", "tim")


43
44
45
46
# File 'lib/followanalytics/attributes.rb', line 43

def set_value(value, key, customer_id)
  hash = attribute_hash(value, key, customer_id)
  send_attributes(hash)
end

#unset_value(key, customer_id) ⇒ Object

Unset one value for a customer.

Examples:

Unset the value “apple” to the attribute with the key “favorite_fruit” for the customer “tim”

client.unset_value("favorite_fruit", "tim")


55
56
57
58
# File 'lib/followanalytics/attributes.rb', line 55

def unset_value(key, customer_id)
  hash = attribute_hash(nil, key, customer_id)
  send_attributes(hash)
end