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