5
5
import logging
6
6
import requests
7
7
8
+ from packet import __version__
9
+
8
10
9
11
class Error (Exception ): # pragma: no cover
10
12
"""Base exception class for this module"""
@@ -47,12 +49,19 @@ class BaseAPI(object):
47
49
Basic api class for
48
50
"""
49
51
50
- def __init__ (self , auth_token , consumer_token ):
52
+ def __init__ (self , auth_token , consumer_token , user_agent = "" ):
51
53
self .auth_token = auth_token
52
54
self .consumer_token = consumer_token
53
55
self .end_point = "api.packet.net"
56
+ self ._user_agent_prefix = user_agent
54
57
self ._log = logging .getLogger (__name__ )
55
58
59
+ @property
60
+ def user_agent (self ):
61
+ return "{}packet-python/{} {}" .format (
62
+ self ._user_agent_prefix , __version__ , requests .utils .default_user_agent ()
63
+ ).strip ()
64
+
56
65
def call_api (self , method , type = "GET" , params = None ): # noqa
57
66
if params is None :
58
67
params = {}
@@ -63,6 +72,7 @@ def call_api(self, method, type="GET", params=None): # noqa
63
72
"X-Auth-Token" : self .auth_token ,
64
73
"X-Consumer-Token" : self .consumer_token ,
65
74
"Content-Type" : "application/json" ,
75
+ "User-Agent" : self .user_agent ,
66
76
}
67
77
68
78
# remove token from log
0 commit comments