Passed
Push — master ( 272d30...b93c80 )
by Steffen
01:01
created

Item.add_sticker()   A

Complexity

Conditions 2

Size

Total Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 2
c 1
b 0
f 1
dl 0
loc 8
rs 9.4285
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, app_id: int, class_id: int, context_id: int, instance_id: int, price: int, wear_value: float,
14
                 image: str, inspect_link: str, stickers: List[Sticker] = None):
15
        """Initializing function
16
17
        :param app_id:
18
        :param class_id:
19
        :param context_id:
20
        :param instance_id:
21
        :param price:
22
        :param wear_value:
23
        :param image:
24
        :param inspect_link:
25
        :param stickers:
26
        """
27
        self._app_id = app_id
28
        self._class_id = class_id
29
        self._context_id = context_id
30
        self._instance_id = instance_id
31
        self._price = price
32
        self._wear_value = wear_value
33
        self._image = image
34
        self._inspect_link = inspect_link
35
36
        if stickers:
37
            self._stickers = stickers
38
        else:
39
            self._stickers = []
40
41
    @property
42
    def value(self):
43
        """Return all important information from the Steam API
44
45
        :return:
46
        """
47
        return {
48
            'app_id': self._app_id,
49
            'class_id': self._class_id,
50
            'context_id': self._context_id,
51
            'instance_id': self._instance_id,
52
            'price': self._price,
53
            'wear_value': self._wear_value,
54
            'image': self._image,
55
            'inspect_link': self._inspect_link,
56
            'stickers': self.stickers
57
        }
58
59
    @property
60
    def stickers(self):
61
        """Property for stickers which returns __dict__ of the sticker objects
62
        to allow JSON dump the item without custom JSONEncoder objects
63
64
        :return:
65
        """
66
        return [s.__dict__ for s in self._stickers]
67
68
    @stickers.setter
69
    def stickers(self, stickers: List[Sticker]):
70
        """Setter for sticker
71
72
        :param stickers:
73
        :return:
74
        """
75
        self._stickers = stickers
76
77
    def add_sticker(self, sticker: Sticker):
78
        """Adder for sticker
79
80
        :param sticker:
81
        :return:
82
        """
83
        if sticker not in self._stickers:
84
            self._stickers.append(sticker)
85