@@ -152,7 +152,7 @@ def import_data(self, api_key, distinct_id, event_name, timestamp,
152152 if meta :
153153 event .update (meta )
154154
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 ) )
156156
157157 def alias (self , alias_id , original , meta = None ):
158158 """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)
221221 }
222222 if meta :
223223 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 ) )
225225
226226 def people_set (self , distinct_id , properties , meta = None ):
227227 """Set properties of a people record.
@@ -572,7 +572,6 @@ def send(self, endpoint, json_message, api_key=None, api_secret=None):
572572 :raises MixpanelException: if the endpoint doesn't exist, the server is
573573 unreachable, or the message cannot be processed
574574
575-
576575 .. versionadded:: 4.8.0
577576 The *api_secret* parameter.
578577 """
@@ -587,6 +586,12 @@ def _write_request(self, request_url, json_message, api_key=None, api_secret=Non
587586 'verbose' : 1 ,
588587 'ip' : 0 ,
589588 }
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+
590595 if api_key :
591596 data .update ({'api_key' : api_key })
592597
@@ -685,6 +690,9 @@ def send(self, endpoint, json_message, api_key=None, api_secret=None):
685690 if endpoint not in self ._buffers :
686691 raise MixpanelException ('No such endpoint "{0}". Valid endpoints are one of {1}' .format (endpoint , self ._buffers .keys ()))
687692
693+ if not isinstance (api_key , tuple ):
694+ api_key = (api_key , api_secret )
695+
688696 buf = self ._buffers [endpoint ]
689697 buf .append (json_message )
690698 # Fixme: Don't stick these in the instance.
@@ -704,11 +712,12 @@ def flush(self):
704712
705713 def _flush_endpoint (self , endpoint ):
706714 buf = self ._buffers [endpoint ]
715+
707716 while buf :
708717 batch = buf [:self ._max_size ]
709718 batch_json = '[{0}]' .format (',' .join (batch ))
710719 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 )
712721 except MixpanelException as orig_e :
713722 mp_e = MixpanelException (orig_e )
714723 mp_e .message = batch_json
0 commit comments