diff --git a/.gitignore b/.gitignore index abac1ee..abae00a 100644 --- a/.gitignore +++ b/.gitignore @@ -34,3 +34,4 @@ nosetests.xml .project .pydevproject .env +.idea/ \ No newline at end of file diff --git a/README.md b/README.md index e1103ac..416b07a 100644 --- a/README.md +++ b/README.md @@ -50,8 +50,11 @@ Listing latest transactions: >>> client.last(from_date='2013-03-01') # sets cursor to given date and returns following transactions ``` -For further information [read code](https://github.com/honzajavorek/fiobank/blob/master/fiobank.py). +## Conflict error +[Fio API documentation](http://www.fio.cz/docs/cz/API_Bankovnictvi.pdf) (Section 8.2) states that a single token should be used only once per 30s. Otherwise a HTTP conflict will be returned and `Fiobank.ThrottlingError` will be raised. + +For further information [read code](https://github.com/honzajavorek/fiobank/blob/master/fiobank.py). ## License: ISC diff --git a/fiobank.py b/fiobank.py index cb06221..c03c891 100644 --- a/fiobank.py +++ b/fiobank.py @@ -6,6 +6,7 @@ import requests + __all__ = ('FioBank',) @@ -26,6 +27,14 @@ def sanitize_value(value, convert=None): return value +class ThrottlingError(Exception): + """ + Throttling error raised when api is being used too fast. + """ + def __str__(self): + return 'Token should be used only once per 30s.' + + class FioBank(object): base_url = 'https://www.fio.cz/ib_api/rest/' @@ -79,6 +88,9 @@ def _request(self, action, **params): url = template.format(token=self.token, **params) response = requests.get(url) + if response.status_code == requests.codes['conflict']: + raise ThrottlingError() + response.raise_for_status() if response.content: @@ -104,7 +116,7 @@ def _parse_info(self, data): def _parse_transactions(self, data): schema = self.transaction_schema try: - entries = data['accountStatement']['transactionList']['transaction'] + entries = data['accountStatement']['transactionList']['transaction'] # noqa except TypeError: entries = [] diff --git a/setup.py b/setup.py index acf47c0..65b7ddd 100644 --- a/setup.py +++ b/setup.py @@ -23,7 +23,7 @@ base_path = os.path.dirname(__file__) -version = '0.0.4' +version = '0.0.5' # release a version, publish to GitHub and PyPI