Skip to content

Commit

Permalink
Add api_key argument as in Mixpanel package v4.3.2
Browse files Browse the repository at this point in the history
The Mixpanel `BufferedConsumer.send` method now has a third argument
`api_key`, that `AsyncBufferedConsumer` has to have too.
  • Loading branch information
bbc2 committed Jul 11, 2019
1 parent 8812984 commit 048cf71
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@ project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

### Added

* Argument `api_key` for `AsyncBufferedConsumer.send`, for compatibility with the version
4.3.2 of the Mixpanel package.

### Changed

* Breaking change: Argument of `flush` renamed from `async` to `async_` for
Expand Down
7 changes: 6 additions & 1 deletion mixpanel_async/async_buffered_consumer.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,7 +133,7 @@ def _should_flush(self, endpoint=None):
return False


def send(self, endpoint, json_message):
def send(self, endpoint, json_message, api_key=None):
'''
Record an event or a profile update. Calls to send() will store
the given message in memory, and (when enough messages have been stored)
Expand All @@ -147,6 +147,8 @@ def send(self, endpoint, json_message):
:type endpoint: str (one of 'events' or 'people')
:param json_message: A json message formatted for the endpoint.
:type json_message: str
:param api_key: Your Mixpanel project's API key
:type api_key: str
:raises: MixpanelException
'''
if endpoint not in self._async_buffers:
Expand All @@ -155,6 +157,9 @@ def send(self, endpoint, json_message):
buf = self._async_buffers[endpoint]
buf.append(json_message)

if api_key is not None:
self._api_key = api_key

should_flush = self._should_flush(endpoint)

if should_flush == self.ALL:
Expand Down
2 changes: 1 addition & 1 deletion tests/async_buffered_consumer_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -148,7 +148,7 @@ def test_does_not_drop_events(self):

self.wait_for_threads()

send_patch.assert_called_once_with(self.ENDPOINT, '[{"test": true}]')
send_patch.assert_called_once_with(self.ENDPOINT, '[{"test": true}]', None)
self.assertEqual(self.consumer._async_buffers[self.ENDPOINT], [self.JSON])

def test_raises_exception_with_bad_endpoint(self):
Expand Down

0 comments on commit 048cf71

Please sign in to comment.