@@ -152,7 +152,7 @@ def import_data(self, api_key, distinct_id, event_name, timestamp,
152
152
if meta :
153
153
event .update (meta )
154
154
155
- self ._consumer .send ('imports' , json_dumps (event , cls = self ._serializer ), api_key , api_secret )
155
+ self ._consumer .send ('imports' , json_dumps (event , cls = self ._serializer ), ( api_key , api_secret ) )
156
156
157
157
def alias (self , alias_id , original , meta = None ):
158
158
"""Creates an alias which Mixpanel will use to remap one id to another.
@@ -221,7 +221,7 @@ def merge(self, api_key, distinct_id1, distinct_id2, meta=None, api_secret=None)
221
221
}
222
222
if meta :
223
223
event .update (meta )
224
- self ._consumer .send ('imports' , json_dumps (event , cls = self ._serializer ), api_key , api_secret )
224
+ self ._consumer .send ('imports' , json_dumps (event , cls = self ._serializer ), ( api_key , api_secret ) )
225
225
226
226
def people_set (self , distinct_id , properties , meta = None ):
227
227
"""Set properties of a people record.
@@ -572,7 +572,6 @@ def send(self, endpoint, json_message, api_key=None, api_secret=None):
572
572
:raises MixpanelException: if the endpoint doesn't exist, the server is
573
573
unreachable, or the message cannot be processed
574
574
575
-
576
575
.. versionadded:: 4.8.0
577
576
The *api_secret* parameter.
578
577
"""
@@ -587,6 +586,12 @@ def _write_request(self, request_url, json_message, api_key=None, api_secret=Non
587
586
'verbose' : 1 ,
588
587
'ip' : 0 ,
589
588
}
589
+
590
+ if isinstance (api_key , tuple ):
591
+ # For compatibility with subclassers, allow the auth details to be
592
+ # packed into the existing api_key param.
593
+ api_key , api_secret = api_key
594
+
590
595
if api_key :
591
596
data .update ({'api_key' : api_key })
592
597
@@ -685,6 +690,9 @@ def send(self, endpoint, json_message, api_key=None, api_secret=None):
685
690
if endpoint not in self ._buffers :
686
691
raise MixpanelException ('No such endpoint "{0}". Valid endpoints are one of {1}' .format (endpoint , self ._buffers .keys ()))
687
692
693
+ if not isinstance (api_key , tuple ):
694
+ api_key = (api_key , api_secret )
695
+
688
696
buf = self ._buffers [endpoint ]
689
697
buf .append (json_message )
690
698
# Fixme: Don't stick these in the instance.
@@ -704,11 +712,12 @@ def flush(self):
704
712
705
713
def _flush_endpoint (self , endpoint ):
706
714
buf = self ._buffers [endpoint ]
715
+
707
716
while buf :
708
717
batch = buf [:self ._max_size ]
709
718
batch_json = '[{0}]' .format (',' .join (batch ))
710
719
try :
711
- self ._consumer .send (endpoint , batch_json , self ._api_key , self . _api_secret )
720
+ self ._consumer .send (endpoint , batch_json , api_key = self ._api_key )
712
721
except MixpanelException as orig_e :
713
722
mp_e = MixpanelException (orig_e )
714
723
mp_e .message = batch_json
0 commit comments