ISales.withdraw_item()   A
last analyzed

Complexity

Conditions 1

Size

Total Lines 16
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1.4218

Importance

Changes 0
Metric Value
eloc 6
dl 0
loc 16
ccs 1
cts 4
cp 0.25
rs 10
c 0
b 0
f 0
cc 1
nop 3
crap 1.4218
1
#!/usr/bin/python
2
# -*- coding: utf-8 -*-
3 1
from typing import Union
4
5 1
from kuon.api_response import APIResponse
6 1
from kuon.bitskins import BitSkins
7 1
from kuon.bitskins.common import *
8 1
from kuon.common import CommonSteamGames
9
10
11 1
class ISales(BitSkins):
12
    """Implementation of the API methods related to market sales of BitSkins
13
14
    common not self explanatory keys:
15
        app id:
16
            The Steam AppID of the game which owns this item (e.g. 730 for CS:GO, 440 for TF2, 570 for Dota 2)
17
        market hash name:
18
            The full market name of the item. For example: "AK-47 | Aquamarine Revenge (Field-Tested)"
19
    """
20
21 1
    def __init__(self, *args, **kwargs) -> None:
22
        """Initializing function
23
24
        :type args: list
25
        :type kwargs: dict
26
        """
27
        super().__init__(*args, **kwargs)
28
29 1
    def get_inventory_on_sale(self, app_id: int = CommonSteamGames.APP_ID_CSGO, page: int = None,
30
                              sort_by: str = Sorting.PRICE, order: str = SortingDirection.ASCENDING,
31
                              market_hash_name: str = None, min_price: int = None, max_price: int = None,
32
                              has_stickers: bool = None, is_stattrak: bool = None, is_souvenir: bool = None,
33
                              per_page: int = None) -> APIResponse:
34
        """GetInventoryOnSale v1 implementation
35
        https://bitskins.com/api/#get_inventory_on_sale
36
37
        :type app_id: int
38
        :type page: int
39
        :type sort_by: str
40
        :type order: str
41
        :type market_hash_name: str
42
        :type min_price: int
43
        :type max_price: int
44
        :type has_stickers: bool
45
        :type is_stattrak: bool
46
        :type is_souvenir: bool
47
        :type per_page: int
48
        :return:
49
        """
50
        arguments = locals()
51
        api_url = "https://bitskins.com/api/v1/get_inventory_on_sale/"
52
53
        payload = {
54
            'app_id': str(app_id)
55
        }
56
57
        for argument in arguments:
58
            if argument == 'self':
59
                continue
60
61
            if arguments[argument] is not None:
62
                payload[argument] = arguments[argument]
63
64
        return self.api_request(api_url=api_url, params=payload)
65
66 1
    def get_sales_info(self, market_hash_name: str, app_id: int = CommonSteamGames.APP_ID_CSGO,
67
                       page: int = None) -> APIResponse:
68
        """GetRecentSaleInfo v1 implementation
69
        https://bitskins.com/api#get_sales_info
70
71
        :type market_hash_name: str
72
        :type page: int
73
        :type app_id: int
74
        :return:
75
        """
76
        api_url = 'https://bitskins.com/api/v1/get_sales_info/'
77
78
        payload = {
79
            'app_id': app_id,
80
            'market_hash_name': market_hash_name
81
        }
82
83
        if page:
84
            payload['page'] = int(page)
85
86
        return self.api_request(api_url=api_url, params=payload)
87
88 1
    def buy_item(self, item_ids: Union[list, tuple], prices: Union[list, tuple],
89
                 app_id: int = CommonSteamGames.APP_ID_CSGO, auto_trade: bool = True) -> APIResponse:
90
        """BuyItem v1 implementation
91
        https://bitskins.com/api#buy_item
92
93
        :type item_ids: Union[list, tuple]
94
        :type prices: Union[list, tuple]
95
        :type app_id: int
96
        :type auto_trade: bool
97
        :return:
98
        """
99
        api_url = 'https://bitskins.com/api/v1/buy_item/'
100
101
        payload = {
102
            'app_id': app_id,
103
            'item_ids': ",".join(item_ids),
104
            'prices': ",".join(prices)
105
        }
106
107
        if not auto_trade:
108
            payload['auto_trade'] = 'false'
109
110
        return self.api_request(api_url=api_url, params=payload)
111
112 1
    def list_item_for_sale(self, item_ids: Union[list, tuple], prices: Union[list, tuple],
113
                           app_id: int = CommonSteamGames.APP_ID_CSGO) -> APIResponse:
114
        """SellItem v1 implementation
115
        https://bitskins.com/api#list_item_for_sale
116
117
        :type item_ids: Union[list, tuple]
118
        :type prices: Union[list, tuple]
119
        :type app_id: int
120
        :return:
121
        """
122
        api_url = 'https://bitskins.com/api/v1/list_item_for_sale/'
123
124
        payload = {
125
            'app_id': app_id,
126
            'item_ids': ",".join(item_ids),
127
            'prices': ",".join(prices)
128
        }
129
130
        return self.api_request(api_url=api_url, params=payload)
131
132 1
    def modify_sale_item(self, item_ids: Union[list, tuple], prices: Union[list, tuple],
133
                         app_id: int = CommonSteamGames.APP_ID_CSGO) -> APIResponse:
134
        """ModifySale v1 implementation
135
        https://bitskins.com/api#modify_sale_item
136
137
        :type item_ids: Union[list, tuple]
138
        :type prices: Union[list, tuple]
139
        :type app_id: int
140
        :return:
141
        """
142
        api_url = 'https://bitskins.com/api/v1/modify_sale_item/'
143
144
        payload = {
145
            'app_id': app_id,
146
            'item_ids': ",".join(item_ids),
147
            'prices': ",".join(prices)
148
        }
149
150
        return self.api_request(api_url=api_url, params=payload)
151
152 1
    def withdraw_item(self, item_ids: Union[list, tuple], app_id: int = CommonSteamGames.APP_ID_CSGO) -> APIResponse:
153
        """WithdrawItem v1 implementation
154
        https://bitskins.com/api#withdraw_item
155
156
        :type item_ids: Union[list, tuple]
157
        :type app_id: int
158
        :return:
159
        """
160
        api_url = 'https://bitskins.com/api/v1/withdraw_item/'
161
162
        payload = {
163
            'app_id': app_id,
164
            'item_ids': ",".join(item_ids)
165
        }
166
167
        return self.api_request(api_url=api_url, params=payload)
168
169 1
    def bump_item(self, item_ids: Union[list, tuple], app_id: int = CommonSteamGames.APP_ID_CSGO) -> APIResponse:
170
        """BumpItem v1 implementation
171
        https://bitskins.com/api#bump_item
172
173
        :type item_ids: Union[list, tuple]
174
        :type app_id:
175
        :return:
176
        """
177
        api_url = 'https://bitskins.com/api/v1/bump_item/'
178
179
        payload = {
180
            'app_id': app_id,
181
            'item_ids': ",".join(item_ids)
182
        }
183
184
        return self.api_request(api_url=api_url, params=payload)
185
186 1
    def get_reset_price_items(self, app_id: int = CommonSteamGames.APP_ID_CSGO, page: int = None) -> APIResponse:
187
        """GetResetPriceItems v1 implementation
188
        https://bitskins.com/api#get_reset_price_items
189
190
        :type app_id: int
191
        :type page: int
192
        :return:
193
        """
194
        api_url = 'https://bitskins.com/api/v1/get_reset_price_items/'
195
196
        payload = {
197
            'app_id': app_id,
198
        }
199
200
        if page:
201
            payload['page'] = int(page)
202
203
        return self.api_request(api_url=api_url, params=payload)
204
205 1
    def get_steam_price_data(self, market_hash_name: str, app_id: int = CommonSteamGames.APP_ID_CSGO) -> APIResponse:
206
        """GetRawPriceData v1 implementation
207
        https://bitskins.com/api#get_steam_price_data
208
209
        Returns the cheapest steam market price
210
211
        :type market_hash_name: str
212
        :type app_id: int
213
        :return:
214
        """
215
        api_url = 'https://bitskins.com/api/v1/get_steam_price_data/'
216
217
        payload = {
218
            'app_id': app_id,
219
            'market_hash_name': market_hash_name
220
        }
221
222
        return self.api_request(api_url=api_url, params=payload)
223
224 1
    def get_specific_items_on_sale(self, item_ids: Union[list, tuple],
225
                                   app_id: int = CommonSteamGames.APP_ID_CSGO) -> APIResponse:
226
        """GetSpecificItemsOnSale v1 implementation
227
        https://bitskins.com/api#get_specific_items_on_sale
228
229
        Returns detailed information of requested items currently on sale on BitSkins
230
231
        :type item_ids: Union[list, tuple]
232
        :type app_id: int
233
        :return:
234
        """
235
        api_url = 'https://bitskins.com/api/v1/get_specific_items_on_sale/'
236
237
        payload = {
238
            'app_id': app_id,
239
            'item_ids': ",".join(item_ids)
240
        }
241
242
        return self.api_request(api_url=api_url, params=payload)
243