forked from luna/vim-rana-local
enable custom base url
This commit is contained in:
parent
13d7f11d80
commit
48f256cb52
|
@ -38,6 +38,11 @@ except ImportError: # pragma: nocover
|
|||
sys.exit(UNKNOWN_ERROR)
|
||||
|
||||
|
||||
def _make_url(configs, path):
|
||||
base_url = configs.get('settings', 'base_url')
|
||||
return '%s/%s' % (base_url, path)
|
||||
|
||||
|
||||
def send_heartbeats(heartbeats, args, configs, use_ntlm_proxy=False):
|
||||
"""Send heartbeats to WakaTime API.
|
||||
|
||||
|
@ -47,9 +52,7 @@ def send_heartbeats(heartbeats, args, configs, use_ntlm_proxy=False):
|
|||
if len(heartbeats) == 0:
|
||||
return SUCCESS
|
||||
|
||||
api_url = args.api_url
|
||||
if not api_url:
|
||||
api_url = 'https://rana.discordapp.io/api/v1/users/current/heartbeats.bulk'
|
||||
api_url = _make_url(configs, '/api/v1/users/current/heartbeats.bulk')
|
||||
log.debug('Sending heartbeats to api at %s' % api_url)
|
||||
timeout = args.timeout
|
||||
if not timeout:
|
||||
|
@ -163,7 +166,7 @@ def send_heartbeats(heartbeats, args, configs, use_ntlm_proxy=False):
|
|||
return AUTH_ERROR if code == 401 else API_ERROR
|
||||
|
||||
|
||||
def get_time_today(args, use_ntlm_proxy=False):
|
||||
def get_time_today(args, configs, use_ntlm_proxy=False):
|
||||
"""Get coding time from WakaTime API for given time range.
|
||||
|
||||
Returns total time as string or `None` when unable to fetch summary from
|
||||
|
@ -171,7 +174,8 @@ def get_time_today(args, use_ntlm_proxy=False):
|
|||
fetch summary.
|
||||
"""
|
||||
|
||||
url = 'https://rana.discordapp.io/api/v1/users/current/summaries'
|
||||
url = _make_url(configs, '/api/v1/users/current/summaries')
|
||||
|
||||
timeout = args.timeout
|
||||
if not timeout:
|
||||
timeout = 60
|
||||
|
@ -219,7 +223,7 @@ def get_time_today(args, use_ntlm_proxy=False):
|
|||
verify=ssl_verify)
|
||||
except RequestException:
|
||||
if should_try_ntlm:
|
||||
return get_time_today(args, use_ntlm_proxy=True)
|
||||
return get_time_today(args, configs, use_ntlm_proxy=True)
|
||||
|
||||
session_cache.delete()
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
|
@ -233,7 +237,7 @@ def get_time_today(args, use_ntlm_proxy=False):
|
|||
|
||||
except: # delete cached session when requests raises unknown exception
|
||||
if should_try_ntlm:
|
||||
return get_time_today(args, use_ntlm_proxy=True)
|
||||
return get_time_today(args, configs, use_ntlm_proxy=True)
|
||||
|
||||
session_cache.delete()
|
||||
if log.isEnabledFor(logging.DEBUG):
|
||||
|
@ -264,7 +268,7 @@ def get_time_today(args, use_ntlm_proxy=False):
|
|||
return None, API_ERROR
|
||||
else:
|
||||
if should_try_ntlm:
|
||||
return get_time_today(args, use_ntlm_proxy=True)
|
||||
return get_time_today(args, configs, use_ntlm_proxy=True)
|
||||
|
||||
session_cache.delete()
|
||||
log.debug({
|
||||
|
|
|
@ -43,7 +43,7 @@ def execute(argv=None):
|
|||
setup_logging(args, __version__)
|
||||
|
||||
if args.today:
|
||||
text, retval = get_time_today(args)
|
||||
text, retval = get_time_today(args, configs)
|
||||
if text:
|
||||
print(text)
|
||||
return retval
|
||||
|
|
Loading…
Reference in New Issue