Skip to content

Commit b5e315a

Browse files
author
Inbal Tako
committed
Add phone field to user traits
1 parent f691d98 commit b5e315a

File tree

7 files changed

+23
-12
lines changed

7 files changed

+23
-12
lines changed

README.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ context = securenative.context_builder(ip = '127.0.0.1', client_token = 'SECURED
100100
headers = { 'user-agent' => 'Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405' })
101101

102102
event_options = EventOptionsBuilder(event_type = EventTypes::LOG_IN,
103-
user_id = '1234', user_traits = UserTraits('Your Name', '[email protected]'),
103+
user_id = '1234', user_traits = UserTraits('Your Name', '[email protected]', '+1234567890'),
104104
context = context, properties = {prop1 => 'CUSTOM_PARAM_VALUE', prop2 => true, prop3 => 3}).build
105105

106106
securenative.track(event_options)
@@ -120,7 +120,7 @@ def track(request)
120120
context = SecureNative.context_builder.from_http_request(request).build
121121

122122
event_options = EventOptionsBuilder(event_type = EventTypes::LOG_IN,
123-
user_id = '1234', user_traits = UserTraits('Your Name', '[email protected]'),
123+
user_id = '1234', user_traits = UserTraits('Your Name', '[email protected]', '+1234567890'),
124124
context = context, properties = {prop1 => 'CUSTOM_PARAM_VALUE', prop2 => true, prop3 => 3}).build
125125

126126
securenative.track(event_options)
@@ -143,7 +143,7 @@ def verify(request)
143143
context = SecureNative.context_builder.from_http_request(request).build
144144

145145
event_options = EventOptionsBuilder(event_type = EventTypes::LOG_IN,
146-
user_id = '1234', user_traits = UserTraits('Your Name', '[email protected]'),
146+
user_id = '1234', user_traits = UserTraits('Your Name', '[email protected]', '+1234567890'),
147147
context = context, properties = {prop1 => 'CUSTOM_PARAM_VALUE', prop2 => true, prop3 => 3}).build
148148

149149
verify_result = securenative.verify(event_options)

VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.1.16
1+
0.1.17

lib/securenative/event_manager.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ def self.serialize(obj)
130130
userTraits: {
131131
name: obj.user_traits.name,
132132
email: obj.user_traits.email,
133+
phone: obj.user_traits.phone,
133134
createdAt: obj.user_traits.created_at
134135
},
135136
request: {

lib/securenative/event_options_builder.rb

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,20 @@
11
class EventOptionsBuilder
22
MAX_PROPERTIES_SIZE = 10
33

4-
def initialize(event_type, user_id, user_traits, user_name, email, created_at, context, properties, timestamp)
4+
def initialize(event_type, user_id, user_traits, user_name, email, phone, created_at, context, properties, timestamp)
5+
traits = UserTraits(user_name)
6+
if user_name && email && phone && created_at
7+
traits = UserTraits(user_name, email, phone, created_at)
8+
elsif user_name && email && phone
9+
traits = UserTraits(user_name, email, phone)
10+
elsif user_name && email
11+
traits = UserTraits(user_name, email)
12+
end
13+
514
@event_options = EventOptions(event_type)
615
@event_options.user_id = user_id
716
@event_options.user_traits = user_traits if user_traits
8-
@event_options.user_traits = UserTraits(name, email, created_at) if user_name && email && created_at
17+
@event_options.user_traits = traits
918
@event_options.context = context
1019
@event_options.properties = properties
1120
@event_options.timestamp = timestamp
Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
class UserTraits
2-
attr_reader :name, :email, :created_at
3-
attr_writer :name, :email, :created_at
2+
attr_reader :name, :email, :phone, :created_at
3+
attr_writer :name, :email, :phone, :created_at
44

5-
def initialize(name = nil, email = nil, created_at = nil)
5+
def initialize(name = nil, email = nil, phone = nil, created_at = nil)
66
@name = name
77
@email = email
88
@created_at = created_at
9+
@phone = phone
910
end
1011
end

spec/spec_api_manager.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@
99
end
1010
let(:event_options) do
1111
EventOptionsBuilder(event_type = EventTypes.LOG_IN, user_id = 'USER_ID',
12-
user_traits = UserTraits('USER_NAME', 'USER_EMAIL'),
12+
user_traits = UserTraits('USER_NAME', 'USER_EMAIL', '+1234567890'),
1313
properties = {prop1: 'CUSTOM_PARAM_VALUE', prop2: true, prop3: 3}).build
1414
end
1515

1616
it 'tracks an event' do
1717
options = ConfigurationBuilder(api_key = 'YOUR_API_KEY', auto_send = true, interval = 10, api_url = 'https://api.securenative-stg.com/collector/api/v1')
1818

1919
expected = '{"eventType":"sn.user.login","userId":"USER_ID","userTraits":{' \
20-
'"name":"USER_NAME","email":"USER_EMAIL","createdAt":null},"request":{' \
20+
'"name":"USER_NAME","email":"USER_EMAIL","phone":"+1234567890","createdAt":null},"request":{' \
2121
'"cid":null,"vid":null,"fp":null,"ip":"127.0.0.1","remoteIp":null,"headers":{' \
2222
'"user-agent":"Mozilla/5.0 (iPad; U; CPU OS 3_2_1 like Mac OS X; en-us) ' \
2323
'AppleWebKit/531.21.10 (KHTML, like Gecko) Mobile/7B405"},"url":null,"method":null},' \

spec/spec_event_manager.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ def initialize
1010
@timestamp = Time.now.strftime('%Y-%m-%dT%H:%M:%S.%L%Z')
1111
@rid = '432532'
1212
@user_id = '1'
13-
@user_traits = UserTraits('some user', '[email protected]')
13+
@user_traits = UserTraits('some user', '[email protected]', '+1234567890')
1414
@request = RequestContext()
1515
@properties = []
1616
end

0 commit comments

Comments
 (0)