@@ -36,20 +36,20 @@ class Rate:
return datetime.datetime.fromtimestamp(value)
@classmethod
def serialize_rates(cls, rates):
return {code: float(rates[code]) for code in rates}
def serialize_timestamp(cls, value):
return int(value.timestamp())
def from_json_file(cls, json_file):
response = json.load(json_file, parse_float=decimal.Decimal)
response = json.load(json_file, parse_int=decimal.Decimal, parse_float=decimal.Decimal)
return cls(**response)
def convert(self, amount, from_currency, to_currency):
return amount * self.rates[to_currency] / self.rates[from_currency]
def serialize(self):
return dict(self.walk_fields(functools.partial(getattr, self), 'serialize'))