| Total Complexity | 3 |
| Total Lines | 33 |
| Duplicated Lines | 0 % |
| Coverage | 46.67% |
| Changes | 0 | ||
| 1 | #!/usr/bin/python |
||
| 2 | # -*- coding: utf-8 -*- |
||
| 3 | 1 | import json |
|
| 4 | |||
| 5 | 1 | from kuon.api_response import APIResponse |
|
| 6 | 1 | from kuon.watcher.adapters.models.sold_history import SoldHistory |
|
| 7 | 1 | from kuon.watcher.adapters.models.sold_item import SoldItem |
|
| 8 | |||
| 9 | |||
| 10 | 1 | class SoldHistoryParser(object): |
|
| 11 | """Parser class to parse the response of the sold history to the unified format""" |
||
| 12 | |||
| 13 | 1 | @staticmethod |
|
| 14 | 1 | def parse(results: dict) -> APIResponse: |
|
| 15 | """Parse the sold history model |
||
| 16 | |||
| 17 | :type results: dict |
||
| 18 | :return: |
||
| 19 | """ |
||
| 20 | response = SoldHistory(success=results['status'] == 'success') |
||
| 21 | for item in results['data']['sales']: |
||
| 22 | wear = item['wear_value'] |
||
| 23 | if wear is None: |
||
| 24 | wear = -1.0 |
||
| 25 | |||
| 26 | sold_item = SoldItem( |
||
| 27 | price=int(float(item['price']) * 100), |
||
| 28 | wear_value=float(wear), |
||
| 29 | sold_at=int(item['sold_at']) |
||
| 30 | ) |
||
| 31 | response.add_sale(sold_item) |
||
| 32 | return APIResponse(json.dumps(response.__dict__)) |
||
| 33 |