55import logging
66import requests
77
8+ from packet import __version__
9+
810
911class Error (Exception ): # pragma: no cover
1012 """Base exception class for this module"""
@@ -47,12 +49,19 @@ class BaseAPI(object):
4749 Basic api class for
4850 """
4951
50- def __init__ (self , auth_token , consumer_token ):
52+ def __init__ (self , auth_token , consumer_token , user_agent = "" ):
5153 self .auth_token = auth_token
5254 self .consumer_token = consumer_token
5355 self .end_point = "api.packet.net"
56+ self ._user_agent_prefix = user_agent
5457 self ._log = logging .getLogger (__name__ )
5558
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+
5665 def call_api (self , method , type = "GET" , params = None ): # noqa
5766 if params is None :
5867 params = {}
@@ -63,6 +72,7 @@ def call_api(self, method, type="GET", params=None): # noqa
6372 "X-Auth-Token" : self .auth_token ,
6473 "X-Consumer-Token" : self .consumer_token ,
6574 "Content-Type" : "application/json" ,
75+ "User-Agent" : self .user_agent ,
6676 }
6777
6878 # remove token from log
0 commit comments