Completed
Push — master ( 72b331...d4b7d2 )
by Steffen
02:14
created

kuon.watcher.adapters.models.item   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 8
eloc 43
dl 0
loc 91
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A Item.__init__() 0 31 2
A Item.add_sticker() 0 8 2
A Item.value() 0 18 1
A Item.stickers() 0 8 1
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3
4
from typing import List
5
6
from kuon.watcher.adapters.models import AbstractEntity
7
from kuon.watcher.adapters.models.sticker import Sticker
8
9
10
class Item(AbstractEntity):
11
    """General Item Class"""
12
13
    def __init__(self, market_name: str, item_id: str, app_id: int, class_id: int, context_id: int, instance_id: int,
14
                 price: int, wear_value: float, image: str, inspect_link: str, stickers: List[Sticker] = None):
15
        """Initializing function
16
17
        :param market_name:
18
        :param item_id:
19
        :param app_id:
20
        :param class_id:
21
        :param context_id:
22
        :param instance_id:
23
        :param price:
24
        :param wear_value:
25
        :param image:
26
        :param inspect_link:
27
        :param stickers:
28
        """
29
        self._market_name = market_name
30
        self._item_id = item_id
31
        self._app_id = app_id
32
        self._class_id = class_id
33
        self._context_id = context_id
34
        self._instance_id = instance_id
35
        self._price = price
36
        self._wear_value = wear_value
37
        self._image = image
38
        self._inspect_link = inspect_link
39
40
        if stickers:
41
            self._stickers = stickers
42
        else:
43
            self._stickers = []
44
45
    @property
46
    def value(self):
47
        """Return all important information from the Steam API
48
49
        :return:
50
        """
51
        return {
52
            'market_name': self._market_name,
53
            'item_id': self._item_id,
54
            'app_id': self._app_id,
55
            'class_id': self._class_id,
56
            'context_id': self._context_id,
57
            'instance_id': self._instance_id,
58
            'price': self._price,
59
            'wear_value': self._wear_value,
60
            'image': self._image,
61
            'inspect_link': self._inspect_link,
62
            'stickers': self.stickers
63
        }
64
65
    @property
66
    def stickers(self):
67
        """Property for stickers which returns __dict__ of the sticker objects
68
        to allow JSON dump the item without custom JSONEncoder objects
69
70
        :return:
71
        """
72
        return [s.__dict__ for s in self._stickers]
73
74
    @stickers.setter
75
    def stickers(self, stickers: List[Sticker]):
76
        """Setter for sticker
77
78
        :param stickers:
79
        :return:
80
        """
81
        self._stickers = stickers
82
83
    def add_sticker(self, sticker: Sticker):
84
        """Adder for sticker
85
86
        :param sticker:
87
        :return:
88
        """
89
        if sticker not in self._stickers:
90
            self._stickers.append(sticker)
91