22
33from securenative .context .context_builder import ContextBuilder
44from securenative .models .request_context import RequestContextBuilder
5+ from securenative .models .user_traits import UserTraits
56from securenative .utils .date_utils import DateUtils
67from securenative .utils .encryption_utils import EncryptionUtils
78
@@ -14,21 +15,34 @@ def __init__(self, event_options, securenative_options):
1415 else :
1516 self .context = ContextBuilder .default_context_builder ().build ()
1617
17- client_token = EncryptionUtils .decrypt (self .context .client_token , securenative_options .api_key )
18+ if self .context .client_token :
19+ client_token = EncryptionUtils .decrypt (self .context .client_token , securenative_options .api_key )
20+ else :
21+ client_token = None
22+
23+ if event_options .user_traits and isinstance (event_options .user_traits , dict ):
24+ user_traits = UserTraits (event_options .user_traits .get ("name" , "" ),
25+ event_options .user_traits .get ("email" , "" ),
26+ event_options .user_traits .get ("phone" , "" ),
27+ event_options .user_traits .get ("created_at" , "" ))
28+ elif event_options .user_traits :
29+ user_traits = event_options .user_traits
30+ else :
31+ user_traits = UserTraits ()
1832
1933 self .rid = str (uuid .uuid4 ())
20- self .event_type = event_options .event . value
21- self .user_id = event_options .user_id
22- self .user_traits = event_options . user_traits
34+ self .event_type = event_options .event if event_options . event else ""
35+ self .user_id = event_options .user_id if event_options . user_id else ""
36+ self .user_traits = user_traits
2337 self .request = RequestContextBuilder () \
2438 .with_cid (client_token .cid if client_token else "" ) \
2539 .with_vid (client_token .vid if client_token else "" ) \
2640 .with_fp (client_token .fp if client_token else "" ) \
27- .with_ip (self .context .ip ) \
28- .with_remote_ip (self .context .remote_ip ) \
29- .with_method (self .context .method ) \
30- .with_url (self .context .url ) \
31- .with_headers (self .context .headers ) \
41+ .with_ip (self .context .ip if self . context . ip else "" ) \
42+ .with_remote_ip (self .context .remote_ip if self . context . remote_ip else "" ) \
43+ .with_method (self .context .method if self . context . method else "" ) \
44+ .with_url (self .context .url if self . context . url else "" ) \
45+ .with_headers (self .context .headers if self . context . headers else None ) \
3246 .build ()
3347
3448 self .timestamp = DateUtils .to_timestamp (event_options .timestamp )
0 commit comments