async def bp_create_listing(self, listings: list, parse: bool = True): if not self.bp_user_token: raise exceptions.KeyNotSetError("bp_user_token") data = {"token": self.bp_user_token, "listings": listings} response = await self.request( "POST", "https://backpack.tf/api/classifieds/list/v1", params=data) if "message" in response: raise exceptions.ResponseMessage(response["message"]) if not parse: return response to_return = {"successful": [], "unsuccessful": {}} if not response["listings"]: return to_return for item, success in response["listings"].items(): if "created" in success: to_return["successful"].append(item) else: to_return["unsuccessful"][item] = success["error"] return to_return
async def bp_my_listings(self, item_names: bool = False, intent=None, inactive: int = 1, parse: bool = True): if not self.bp_user_token: raise exceptions.KeyNotSetError("bp_user_token") data = {"token": self.bp_user_token, "inactive": inactive} if item_names: data["item_names"] = True if type(intent) == int: data["intent"] = intent response = await self.request( "GET", "https://backpack.tf/api/classifieds/listings/v1", params=data) if "message" in response: raise exceptions.ResponseMessage(response["message"]) if not parse: return response return bp_classifieds.MyListings(response)
async def bp_send_heartbeat(self, automatic: str = "all"): if not self.bp_user_token: raise exceptions.KeyNotSetError("bp_user_token") data = {"token": self.bp_user_token, "automatic": automatic} response = await self.request( "POST", "https://backpack.tf/api/aux/heartbeat/v1", params=data) if "message" in response: raise exceptions.ResponseMessage(response["message"]) return response["bumped"]
async def bp_get_user_token(self): if not self.bp_api_key: raise exceptions.KeyNotSetError("bp_api_key") data = {"key": self.bp_api_key} response = await self.request("GET", "https://backpack.tf/api/aux/token/v1", params=data) if "message" in response: raise exceptions.ResponseMessage(response["message"]) return response["token"]
async def bp_delete_listings(self, listing_ids, parse: bool = True): if not self.bp_user_token: raise exceptions.KeyNotSetError("bp_user_token") data = {"token": self.bp_user_token, "listing_ids": listing_ids} response = await self.request( "DELETE", "https://backpack.tf/api/classifieds/delete/v1", params=data) if "message" in response: raise exceptions.ResponseMessage(response["message"]) if not parse: return response return response["deleted"], response["errors"]
async def bp_classifieds_search(self, data: dict, parse: bool = True): # backpack.tf docs - https://backpack.tf/api/docs/classifieds_search if not self.bp_api_key: raise exceptions.KeyNotSetError("bp_api_key") data["key"] = self.bp_api_key response = await self.request( "GET", "https://backpack.tf/api/classifieds/search/v1", params=data) if "response" in response: raise exceptions.ResponseMessage(response["response"]) if not parse: return response return bp_classifieds.Classifieds(response)