Skip to content

Commit 00d4461

Browse files
committed
include organizationId, timestamp, and failed for bulk creation
1 parent 219543f commit 00d4461

2 files changed

Lines changed: 72 additions & 18 deletions

File tree

identify/main/identify_sync_client.py

Lines changed: 16 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ def delete_attribute_from_schema(self, traffic_type_id, attribute_id):
9292
'''
9393
return Attribute.delete(self._client, attribute_id, traffic_type_id)
9494

95-
def add_identities(self, traffic_type_id, environment_id, identities):
95+
def add_identities(self, traffic_type_id, environment_id, identities,
96+
organization_id=None):
9697
'''
9798
Create Identities for a specific traffic type and environment.
9899
@@ -115,10 +116,12 @@ def add_identities(self, traffic_type_id, environment_id, identities):
115116
self._client,
116117
traffic_type_id,
117118
environment_id,
118-
identities
119+
identities,
120+
organization_id
119121
)
120122

121-
def add_identity(self, traffic_type_id, environment_id, key, values):
123+
def add_identity(self, traffic_type_id, environment_id, key, values,
124+
organization_id=None):
122125
'''
123126
Create a new Identity.
124127
@@ -137,10 +140,12 @@ def add_identity(self, traffic_type_id, environment_id, key, values):
137140
key,
138141
traffic_type_id,
139142
environment_id,
140-
values
143+
values,
144+
organization_id
141145
)
142146

143-
def update_identity(self, traffic_type_id, environment_id, key, values):
147+
def update_identity(self, traffic_type_id, environment_id, key, values,
148+
organization_id=None):
144149
'''
145150
Update an Identity.
146151
@@ -159,10 +164,12 @@ def update_identity(self, traffic_type_id, environment_id, key, values):
159164
key,
160165
traffic_type_id,
161166
environment_id,
162-
values
167+
values,
168+
organization_id
163169
)
164170

165-
def patch_identity(self, traffic_type_id, environment_id, key, values):
171+
def patch_identity(self, traffic_type_id, environment_id, key, values,
172+
organization_id=None):
166173
'''
167174
Patch an Identity.
168175
@@ -181,7 +188,8 @@ def patch_identity(self, traffic_type_id, environment_id, key, values):
181188
key,
182189
traffic_type_id,
183190
environment_id,
184-
values
191+
values,
192+
organization_id
185193
)
186194

187195
def delete_attributes_from_key(self, traffic_type_id, environment_id, key):

identify/resources/identity.py

Lines changed: 56 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -77,17 +77,21 @@ class Identity(BaseResource):
7777
'trafficTypeId': 'string',
7878
'environmentId': 'string',
7979
'values': 'object',
80+
'organizationId': 'string',
81+
'timestamp': 'string',
8082
}
8183

8284
def __init__(self, client, key, traffic_type_id, environment_id,
83-
values=None):
85+
values=None, organization_id=None, timestamp=None):
8486
'''
8587
'''
8688
BaseResource.__init__(self, client, key)
8789
self._traffic_type_id = traffic_type_id
8890
self._key = key
8991
self._environment_id = environment_id
9092
self._values = values
93+
self._organization_id = organization_id
94+
self._timestamp = timestamp
9195

9296
@property
9397
def key(self):
@@ -105,14 +109,23 @@ def environment_id(self):
105109
def values(self):
106110
return self._values
107111

112+
@property
113+
def organization_id(self):
114+
return self._organization_id
115+
116+
@property
117+
def timestamp(self):
118+
return self._timestamp
119+
108120
@classmethod
109121
def _build_single_from_collection_response(cls, client, response):
110122
'''
111123
'''
112124
raise MethodNotApplicable()
113125

114126
@classmethod
115-
def create(cls, client, key, traffic_type_id, environment_id, values):
127+
def create(cls, client, key, traffic_type_id, environment_id, values,
128+
organization_id=None):
116129
'''
117130
'''
118131
try:
@@ -122,6 +135,7 @@ def create(cls, client, key, traffic_type_id, environment_id, values):
122135
'key': key,
123136
'trafficTypeId': traffic_type_id,
124137
'environmentId': environment_id,
138+
'organization_id': organization_id,
125139
'values': values
126140
},
127141
key=key,
@@ -140,11 +154,14 @@ def create(cls, client, key, traffic_type_id, environment_id, values):
140154
response['key'],
141155
response['trafficTypeId'],
142156
response['environmentId'],
143-
response['values']
157+
response['values'],
158+
response['organizationId'],
159+
response['timestamp']
144160
)
145161

146162
@classmethod
147-
def create_many(cls, client, traffic_type_id, environment_id, identities):
163+
def create_many(cls, client, traffic_type_id, environment_id, identities,
164+
organization_id=None):
148165
'''
149166
entities: { key: { attr_id: value, ...} }
150167
'''
@@ -157,20 +174,42 @@ def create_many(cls, client, traffic_type_id, environment_id, identities):
157174
'key': key,
158175
'trafficTypeId': traffic_type_id,
159176
'environmentId': environment_id,
177+
'organizationId': organization_id,
160178
'values': identities[key]
161179
}
162180
for key in identities.keys()
163181
],
164182
trafficTypeId=traffic_type_id,
165183
environmentId=environment_id
166184
)
167-
return [
185+
186+
successful = [
168187
Identity(
169188
client, i['key'], i['trafficTypeId'],
170-
i['environmentId'], i['values']
189+
i['environmentId'], i['values'], i['organizationId'],
190+
i['timestamp']
171191
) for i in response['objects']
172192
]
173193

194+
failed = [
195+
{
196+
'object': Identity(
197+
client,
198+
i['object']['key'],
199+
i['object']['trafficTypeId'],
200+
i['object']['environmentId'],
201+
i['object']['values'],
202+
i['object']['organizationId'],
203+
i['object']['timestamp']
204+
),
205+
'status': i['status'],
206+
'message': i['message']
207+
}
208+
for i in response['failed']
209+
]
210+
211+
return successful, failed
212+
174213
except HTTPResponseError as e:
175214
LOGGER.error('Call to Identify API failed. Identities not created.')
176215
raise e
@@ -179,7 +218,8 @@ def create_many(cls, client, traffic_type_id, environment_id, identities):
179218
raise UnknownIdentifyClientError()
180219

181220
@classmethod
182-
def update(cls, client, key, traffic_type_id, environment_id, values):
221+
def update(cls, client, key, traffic_type_id, environment_id, values,
222+
organization_id):
183223
'''
184224
'''
185225
try:
@@ -189,6 +229,7 @@ def update(cls, client, key, traffic_type_id, environment_id, values):
189229
'key': key,
190230
'trafficTypeId': traffic_type_id,
191231
'environmentId': environment_id,
232+
'organizationId': organization_id,
192233
'values': values
193234
},
194235
key=key,
@@ -207,11 +248,13 @@ def update(cls, client, key, traffic_type_id, environment_id, values):
207248
response['key'],
208249
response['trafficTypeId'],
209250
response['environmentId'],
210-
response['values']
251+
response['values'],
252+
response['timestamp']
211253
)
212254

213255
@classmethod
214-
def patch(cls, client, key, traffic_type_id, environment_id, values):
256+
def patch(cls, client, key, traffic_type_id, environment_id, values,
257+
organization_id):
215258
'''
216259
'''
217260
try:
@@ -221,6 +264,7 @@ def patch(cls, client, key, traffic_type_id, environment_id, values):
221264
'key': key,
222265
'trafficTypeId': traffic_type_id,
223266
'environmentId': environment_id,
267+
'organizationId': organization_id,
224268
'values': values
225269
},
226270
key=key,
@@ -239,7 +283,9 @@ def patch(cls, client, key, traffic_type_id, environment_id, values):
239283
response['key'],
240284
response['trafficTypeId'],
241285
response['environmentId'],
242-
response['values']
286+
response['values'],
287+
response['organization_id'],
288+
response['timestamp']
243289
)
244290

245291
@classmethod

0 commit comments

Comments
 (0)