Skip to content

Commit

Permalink
ensure we specify the funding instrument used on debits, credits, and…
Browse files Browse the repository at this point in the history
… holds. pep8
  • Loading branch information
Balanced Marshall committed Dec 11, 2012
1 parent 638e9e2 commit dbd5eb5
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 19 deletions.
4 changes: 2 additions & 2 deletions balanced/__init__.py
@@ -1,4 +1,4 @@
__version__ = '0.9.2' __version__ = '0.9.3'
from collections import defaultdict from collections import defaultdict
import contextlib import contextlib


Expand All @@ -25,7 +25,7 @@
Card.__name__, Card.__name__,
BankAccount.__name__, BankAccount.__name__,
exc.__name__.partition('.')[-1], exc.__name__.partition('.')[-1],
] ]


http_client = HTTPClient() http_client = HTTPClient()
config = http_client.config config = http_client.config
Expand Down
6 changes: 3 additions & 3 deletions balanced/config.py
Expand Up @@ -24,9 +24,9 @@ def __init__(self):
'Accept': 'application/json', 'Accept': 'application/json',
'Content-Type': 'application/json', 'Content-Type': 'application/json',
'User-agent': _make_user_agent(), 'User-agent': _make_user_agent(),
}, },
'danger_mode': True, 'danger_mode': True,
} }


@property @property
def uri(self): def uri(self):
Expand Down
18 changes: 9 additions & 9 deletions balanced/http_client.py
Expand Up @@ -10,12 +10,12 @@


serializers = { serializers = {
'application/json': to_json 'application/json': to_json
} }




deserializers = { deserializers = {
'application/json': json.loads 'application/json': json.loads
} }




REDIRECT_STATI = list(REDIRECT_STATI) REDIRECT_STATI = list(REDIRECT_STATI)
Expand All @@ -40,17 +40,17 @@ def wrapped():
raise redirection raise redirection
deserialized = http_client.deserialize( deserialized = http_client.deserialize(
response_instance response_instance
) )
response_instance.deserialized = deserialized response_instance.deserialized = deserialized
extra = deserialized.get('additional') or '' extra = deserialized.get('additional') or ''
if extra: if extra:
extra = ' -- {}.'.format(extra) extra = ' -- {}.'.format(extra)
error_msg = '{name}: {code}: {msg} {extra}'.format( error_msg = '{name}: {code}: {msg} {extra}'.format(
name=deserialized['status'], name=deserialized['status'],
code=deserialized['status_code'], code=deserialized['status_code'],
msg=deserialized['description'].encode('utf8'), msg=deserialized['description'].encode('utf8'),
extra=extra.encode('utf8'), extra=extra.encode('utf8'),
) )
http_error = HTTPError(error_msg) http_error = HTTPError(error_msg)
for error, value in response_instance.deserialized.iteritems(): for error, value in response_instance.deserialized.iteritems():
setattr(http_error, error, value) setattr(http_error, error, value)
Expand Down Expand Up @@ -94,7 +94,7 @@ def make_absolute_url(client, url, **kwargs):
kwargs['allow_redirects'] = False kwargs['allow_redirects'] = False
kwargs['hooks'] = { kwargs['hooks'] = {
'response': wrap_raise_for_status(client) 'response': wrap_raise_for_status(client)
} }


if client.config.api_key_secret: if client.config.api_key_secret:
kwargs['auth'] = (client.config.api_key_secret, None) kwargs['auth'] = (client.config.api_key_secret, None)
Expand Down
7 changes: 6 additions & 1 deletion balanced/resources.py
Expand Up @@ -927,6 +927,7 @@ def debit(self, amount=None, appears_on_statement_as=None,
hold_uri=hold_uri, hold_uri=hold_uri,
meta=meta, meta=meta,
description=description, description=description,
source_uri=self.uri,
).save() ).save()


def hold(self, amount, meta=None, description=None): def hold(self, amount, meta=None, description=None):
Expand All @@ -940,7 +941,8 @@ def hold(self, amount, meta=None, description=None):
uri=self.account.holds_uri, uri=self.account.holds_uri,
amount=amount, amount=amount,
meta=meta, meta=meta,
description=description description=description,
source_uri=self.uri,
).save() ).save()




Expand Down Expand Up @@ -974,6 +976,7 @@ def debit(self, amount, appears_on_statement_as=None,
appears_on_statement_as=appears_on_statement_as, appears_on_statement_as=appears_on_statement_as,
meta=meta, meta=meta,
description=description, description=description,
source_uri=self.uri,
).save() ).save()


def credit(self, amount, description=None, meta=None): def credit(self, amount, description=None, meta=None):
Expand All @@ -992,12 +995,14 @@ def credit(self, amount, description=None, meta=None):
uri = self.account.credits_uri uri = self.account.credits_uri
else: else:
uri = self.credits_uri uri = self.credits_uri
destination_uri = self.uri


credit = Credit( credit = Credit(
uri=uri, uri=uri,
amount=amount, amount=amount,
description=description, description=description,
meta=meta, meta=meta,
destination_uri=destination_uri,
) )
credit.save() credit.save()
return credit return credit
Expand Down
8 changes: 4 additions & 4 deletions balanced/utils.py
Expand Up @@ -236,11 +236,11 @@ def __call__(self, serializable):
for serializer in self.serialization_chain: for serializer in self.serialization_chain:
result = serializer(serializable) result = serializer(serializable)
if ((not self.explicit_none_check and result) or if ((not self.explicit_none_check and result) or
(self.explicit_none_check and result is not None)): (self.explicit_none_check and result is not None)):
return result return result


error_msg = _JSON_ERROR_MSG.format(type(serializable), error_msg = _JSON_ERROR_MSG.format(type(serializable),
repr(serializable)) repr(serializable))
raise TypeError(error_msg) raise TypeError(error_msg)




Expand All @@ -258,8 +258,8 @@ def handle_datetime(serializable):


def to_json(*args, **kwargs): def to_json(*args, **kwargs):
return json.dumps(dict(*args, **kwargs), return json.dumps(dict(*args, **kwargs),
use_decimal=True, use_decimal=True,
default=json_serializer) default=json_serializer)




def urljoin(*args): def urljoin(*args):
Expand Down

1 comment on commit dbd5eb5

@mahmoudimus
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

+1 looks good to me

Please sign in to comment.