Completed
Push — master ( 7f328c...e44757 )
by Steffen
03:00
created

BitSkinsSalesAdapter.get_sold_history()   A

Complexity

Conditions 2

Size

Total Lines 12
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 4.048

Importance

Changes 0
Metric Value
eloc 5
dl 0
loc 12
ccs 1
cts 5
cp 0.2
rs 10
c 0
b 0
f 0
cc 2
nop 3
crap 4.048
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3 1
from kuon.api_response import APIResponse
4 1
from kuon.bitskins.api.interfaces import ISales
5 1
from kuon.watcher.adapters import SalesAdapterBase
6 1
from kuon.watcher.adapters.bitskins.parser import SearchResponseParser, SoldHistoryParser
7
8
9 1
class BitSkinsSalesAdapter(SalesAdapterBase):
10
    """Adapter for the Sales Interface of BitSkins"""
11
12 1
    def __init__(self, *args, **kwargs) -> None:
13
        """Initializing function
14
15
        :type args: list
16
        :type kwargs: dict
17
        """
18
        super().__init__(*args, **kwargs)
19
        self.sales_interface = ISales(*args, **kwargs)
20
21 1
    def search(self, market_name, no_delay=False) -> APIResponse:
22
        """Implementation of the search function
23
24
        :type market_name: str
25
        :type no_delay: bool
26
        :return:
27
        """
28
        return SearchResponseParser.parse(self.sales_interface.get_inventory_on_sale(market_hash_name=market_name))
29
30 1
    def get_sold_history(self, market_name, no_delay=False) -> APIResponse:
31
        """Implementation of get sold history function
32
33
        :type market_name: str
34
        :type no_delay: bool
35
        :return:
36
        """
37
        search_results = self.search(market_name=market_name).data.market_items
38
        if search_results:
39
            market_name = search_results[0].market_name
40
41
        return SoldHistoryParser.parse(self.sales_interface.get_sales_info(market_hash_name=market_name))
42
43 1
    @staticmethod
44 1
    def get_item_link(item_id: str) -> str:
45
        """Generate the item link from the item id
46
47
        :type item_id: str
48
        :return:
49
        """
50
        return "https://bitskins.com/view_item?item_id={0:s}".format(item_id)
51