Add default_return_value
This commit is contained in:
parent
4327ff30df
commit
1e276778f6
1 changed files with 13 additions and 7 deletions
|
|
@ -226,13 +226,18 @@ class Twython(object):
|
||||||
|
|
||||||
# End Dynamic Request Methods
|
# End Dynamic Request Methods
|
||||||
|
|
||||||
def get_lastfunction_header(self, header):
|
def get_lastfunction_header(self, header, default_return_value = None):
|
||||||
"""Returns the header in the last function
|
"""Returns the header in the last function
|
||||||
This must be called after an API call, as it returns header based
|
This must be called after an API call, as it returns header based
|
||||||
information.
|
information.
|
||||||
|
|
||||||
This will return None if the header is not present
|
This will return None if the header is not present
|
||||||
|
|
||||||
|
If default_return_value is set, that will be returned versus throwing
|
||||||
|
a TwythonError exception.
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
Most useful for the following header information:
|
Most useful for the following header information:
|
||||||
x-rate-limit-limit
|
x-rate-limit-limit
|
||||||
x-rate-limit-remaining
|
x-rate-limit-remaining
|
||||||
|
|
@ -240,12 +245,13 @@ class Twython(object):
|
||||||
x-rate-limit-reset
|
x-rate-limit-reset
|
||||||
"""
|
"""
|
||||||
if self._last_call is None:
|
if self._last_call is None:
|
||||||
raise TwythonError('This function must be called after an API call. It delivers header information.')
|
if default_return_value is None:
|
||||||
|
raise TwythonError('This function must be called after an API call. It delivers header information.')
|
||||||
|
else:
|
||||||
|
return default_return_value
|
||||||
|
|
||||||
|
return self._last_call['headers'].get(header, default_return_value)
|
||||||
|
|
||||||
if header in self._last_call['headers']:
|
|
||||||
return self._last_call['headers'][header]
|
|
||||||
else:
|
|
||||||
return None
|
|
||||||
|
|
||||||
def get_authentication_tokens(self, callback_url=None, force_login=False, screen_name=''):
|
def get_authentication_tokens(self, callback_url=None, force_login=False, screen_name=''):
|
||||||
"""Returns a dict including an authorization URL (auth_url) to direct a user to
|
"""Returns a dict including an authorization URL (auth_url) to direct a user to
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue