Skip to content

Commit fa32e1e

Browse files
authored
Merge pull request #13 from honzajavorek/honzajavorek/conflict
Handle HTTP 409 (conflict) responses
2 parents e44bddb + f512fe4 commit fa32e1e

File tree

2 files changed

+21
-11
lines changed

2 files changed

+21
-11
lines changed

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# fiobank
22

3-
[![PyPI version](https://badge.fury.io/py/redis-collections.svg)](https://badge.fury.io/py/redis-collections)
3+
[![PyPI version](https://badge.fury.io/py/fiobank.svg)](https://badge.fury.io/py/fiobank)
44
[![Build Status](https://travis-ci.org/honzajavorek/fiobank.svg?branch=master)](https://travis-ci.org/honzajavorek/fiobank)
55

66
[Fio Bank API](http://www.fio.cz/bank-services/internetbanking-api) in Python.
@@ -49,8 +49,8 @@ Listing latest transactions:
4949
>>> client.last(from_date='2013-03-01') # sets cursor to given date and returns following transactions
5050
```
5151

52-
For further information [read code](https://github.com/honzajavorek/fiobank/blob/master/fiobank.py).
53-
52+
## Conflict Error
53+
[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 409 Conflict will be returned and `fiobank.ThrottlingError` will be raised.
5454

5555
## License: ISC
5656

fiobank.py

+18-8
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import requests
1111

1212

13-
__all__ = ('FioBank',)
13+
__all__ = ('FioBank', 'ThrottlingError')
1414

1515

1616
str = six.text_type
@@ -33,6 +33,13 @@ def sanitize_value(value, convert=None):
3333
return value
3434

3535

36+
class ThrottlingError(Exception):
37+
"""Throttling error raised when api is being used too fast."""
38+
39+
def __str__(self):
40+
return 'Token should be used only once per 30s.'
41+
42+
3643
class FioBank(object):
3744

3845
base_url = 'https://www.fio.cz/ib_api/rest/'
@@ -47,25 +54,25 @@ class FioBank(object):
4754

4855
# http://www.fio.cz/xsd/IBSchema.xsd
4956
transaction_schema = {
50-
'column22': ('transaction_id', str),
5157
'column0': ('date', coerce_date),
5258
'column1': ('amount', float),
53-
'column14': ('currency', str),
5459
'column2': ('account_number', str),
55-
'column10': ('account_name', str),
5660
'column3': ('bank_code', str),
57-
'column26': ('bic', str),
58-
'column12': ('bank_name', str),
5961
'column4': ('constant_symbol', str),
6062
'column5': ('variable_symbol', str),
6163
'column6': ('specific_symbol', str),
6264
'column7': ('user_identification', str),
63-
'column16': ('recipient_message', str),
6465
'column8': ('type', str),
6566
'column9': ('executor', str),
67+
'column10': ('account_name', str),
68+
'column12': ('bank_name', str),
69+
'column14': ('currency', str),
70+
'column16': ('recipient_message', str),
71+
'column17': ('instruction_id', str),
6672
'column18': ('specification', str),
73+
'column22': ('transaction_id', str),
6774
'column25': ('comment', str),
68-
'column17': ('instruction_id', str),
75+
'column26': ('bic', str),
6976
}
7077

7178
info_schema = {
@@ -87,6 +94,9 @@ def _request(self, action, **params):
8794
url = template.format(token=self.token, **params)
8895

8996
response = requests.get(url)
97+
if response.status_code == requests.codes['conflict']:
98+
raise ThrottlingError()
99+
90100
response.raise_for_status()
91101

92102
if response.content:

0 commit comments

Comments
 (0)