forked from segmentio/analytics-python
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path__init__.py
More file actions
59 lines (41 loc) · 1.85 KB
/
__init__.py
File metadata and controls
59 lines (41 loc) · 1.85 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import version
VERSION = version.VERSION
__version__ = VERSION
import sys
this_module = sys.modules[__name__]
from stats import Statistics
stats = Statistics()
methods = ['identify', 'track', 'alias', 'flush', 'on_success', 'on_failure']
def uninitialized(*args, **kwargs):
print >>sys.stderr, 'Please call analytics.init(secret) before calling analytics methods.'
for method in methods:
setattr(this_module, method, uninitialized)
def init(secret, **kwargs):
"""Create a default instance of a analytics-python client
:param str secret: The Segment.io API Secret
Kwargs:
:param logging.LOG_LEVEL log_level: The logging log level for the client
talks to. Use log_level=logging.DEBUG to troubleshoot
: param bool log: False to turn off logging completely, True by default
: param int flush_at: Specicies after how many messages the client will flush
to the server. Use flush_at=1 to disable batching
: param datetime.timedelta flush_after: Specifies after how much time
of no flushing that the server will flush. Used in conjunction with
the flush_at size policy
: param bool async: True to have the client flush to the server on another
thread, therefore not blocking code (this is the default). False to
enable blocking and making the request on the calling thread.
"""
from client import Client
# if we have already initialized, no-op
if hasattr(this_module, 'default_client'):
return
default_client = Client(secret=secret, stats=stats, **kwargs)
setattr(this_module, 'default_client', default_client)
def proxy(method):
def proxy_to_default_client(*args, **kwargs):
func = getattr(default_client, method)
return func(*args, **kwargs)
setattr(this_module, method, proxy_to_default_client)
for method in methods:
proxy(method)