diff --git a/README.md b/README.md index 72faaf0..356c84d 100644 --- a/README.md +++ b/README.md @@ -16,43 +16,43 @@ For now, the implemented function is listed below: * auth - * βœ… sign in + * πŸ”² sign in * πŸ†– register * πŸ†– restore password * profile - * βœ… get current user's profile + * πŸ”² get current user's profile * πŸ”² manage current user profile - * βœ… get a user's profile + * πŸ”² get a user's profile * πŸ”² get all of a user's achievements * πŸ”² get all of a user's reviews - * βœ… set current user's online/offline status + * πŸ”² set current user's online/offline status * items * βœ… list all tradable items * βœ… get info about an item * statistics - * βœ… get statistics of an item + * πŸ”² get statistics of an item * πŸ”² get global market statistics * orders - * βœ… get orders of a single item + * πŸ”² get orders of a single item * πŸ”² get orders for the last 4 hours - * βœ… update a single order on the current profile - * βœ… delete a single order on the current profile - * βœ… add a new order for the current profile + * πŸ”² update a single order on the current profile + * πŸ”² delete a single order on the current profile + * πŸ”² add a new order for the current profile * πŸ”² get user's sale statistics(closed orders) - * βœ… get all of a user's orders + * πŸ”² get all of a user's orders * liches - * βœ… list all lich weapons - * βœ… list all lich ephemeras - * βœ… list all lich quirks + * πŸ”² list all lich weapons + * πŸ”² list all lich ephemeras + * πŸ”² list all lich quirks * rivens - * βœ… list all riven items - * βœ… get a list of riven attributes + * πŸ”² list all riven items + * πŸ”² get a list of riven attributes * misc * πŸ”² get a list of all known game locations * πŸ”² get a list of all known npcs * πŸ”² get a list of all known missions * auctions - * βœ… create auction ⚠️ + * πŸ”² create auction * πŸ”² get a list of riven auctions by given search params * πŸ”² get a list of lich auctions by given search params * auction entry️ diff --git a/src/pywmapi/auth/models.py b/src/pywmapi/auth/models.py index b14f66a..29b76fd 100644 --- a/src/pywmapi/auth/models.py +++ b/src/pywmapi/auth/models.py @@ -109,10 +109,10 @@ class Status(Enum): id: str status: Status - region: str + locale: str reputation: int - last_seen: datetime - ingame_name: Optional[str] = None + lastSeen: datetime + ingameName: Optional[str] = None """In-game name. Only get this field when `verification=True`.""" avatar: Optional[str] = None diff --git a/src/pywmapi/common/__init__.py b/src/pywmapi/common/__init__.py index 1e6a799..5282b44 100644 --- a/src/pywmapi/common/__init__.py +++ b/src/pywmapi/common/__init__.py @@ -2,5 +2,5 @@ from .enums import * from .models import * -API_BASE_URL = "https://api.warframe.market/v1" +API_BASE_URL = "https://api.warframe.market/v2" WSS_BASE_URL = "wss://warframe.market/socket" diff --git a/src/pywmapi/items/api.py b/src/pywmapi/items/api.py index f471e97..039b33d 100644 --- a/src/pywmapi/items/api.py +++ b/src/pywmapi/items/api.py @@ -28,7 +28,7 @@ def list_items(lang: Language = Language.en) -> List[ItemShort]: headers={"Language": lang.value}, ) check_wm_response(res) - return list(map(lambda x: ItemShort.from_dict(x), res.json()["payload"]["items"])) + return list(map(lambda x: ItemShort.from_dict(x), res.json()["data"])) def get_item(url_name: str, platform: Platform = Platform.pc) -> Tuple[ItemFull, List[ItemFull]]: @@ -46,8 +46,8 @@ def get_item(url_name: str, platform: Platform = Platform.pc) -> Tuple[ItemFull, headers={"Platform": platform.value}, ) check_wm_response(res) - item_json = res.json()["payload"]["item"] - return _transform_item_result(item_json) + item_json = res.json()["data"] + return ItemFull.from_dict(item_json) def get_orders(*args, **kwargs): diff --git a/src/pywmapi/items/models.py b/src/pywmapi/items/models.py index 16e9438..1f125a7 100644 --- a/src/pywmapi/items/models.py +++ b/src/pywmapi/items/models.py @@ -15,9 +15,18 @@ @define class ItemShort(ModelBase): id: str - url_name: str + slug: str thumb: str - item_name: str + item_slug: str + + @classmethod + def from_dict(cls, data: dict) -> "ItemShort": + return cls( + id=data["id"], + slug=data["slug"], + thumb=data["i18n"]["en"]["thumb"], + item_slug=data["i18n"]["en"]["name"], + ) @define @@ -32,8 +41,8 @@ class Rarity(Enum): id: str """Item ID.""" - url_name: str - """Item URL name.""" + slug: str + """Item URL slug.""" icon: str thumb: str tags: List[str] @@ -66,3 +75,25 @@ class Rarity(Enum): es: Optional[LangInItem] = None it: Optional[LangInItem] = None pl: Optional[LangInItem] = None + + @classmethod + def from_dict(cls, data: dict) -> "ItemShort": + return cls( + id=data.get("id"), + slug=data.get("slug"), + icon=data["i18n"]["en"].get("icon"), + thumb=data["i18n"]["en"].get("thumb"), + tags=data.get("tags"), + trading_tax=data.get("tradingTax"), + sub_icon=data["i18n"]["en"].get("subIcon"), + quantity_for_set=data.get("quantityInSet"), + mod_max_rank=data.get("maxRank"), + subtypes=data.get("subtypes"), + cyan_stars=data.get("cyanStars"), + amber_stars=data.get("amberStars"), + vaulted=data.get("vaulted"), + ducats=data.get("ducats"), + set_root=data.get("setRoot"), + mastery_level=data.get("reqMasteryRank"), + rarity=cls.Rarity(data["rarity"]) if "rarity" in data else None, + ) diff --git a/src/pywmapi/orders/api.py b/src/pywmapi/orders/api.py index 38fffc2..3e88a83 100644 --- a/src/pywmapi/orders/api.py +++ b/src/pywmapi/orders/api.py @@ -56,13 +56,13 @@ def get_orders( as the 2nd and 3rd return value. """ res = requests.get( - API_BASE_URL + f"/items/{url_name}/orders", + API_BASE_URL + f"/orders/item/{url_name}", params={"include": include.value if include is not None else None}, headers={"Platform": platform.value}, ) check_wm_response(res) json_obj = res.json() - orders = list(map(lambda x: OrderRow.from_dict(x), json_obj["payload"]["orders"])) + orders = list(map(lambda x: OrderRow.from_dict(x), json_obj["data"])) if include == IncludeOption.item: target_item, items_in_set = _transform_item_result(json_obj["include"]["item"]) return orders, target_item, items_in_set diff --git a/src/pywmapi/orders/models.py b/src/pywmapi/orders/models.py index 147f9c9..19c07d7 100644 --- a/src/pywmapi/orders/models.py +++ b/src/pywmapi/orders/models.py @@ -23,7 +23,7 @@ class OrderCommon(ModelBase): id: str platinum: int quantity: int - order_type: OrderType + type: OrderType visible: bool platform: Optional[Platform] = None region: Optional[str] = None @@ -101,7 +101,7 @@ class OrderNewItem(OrderNewItemBase): """ item_id: str - order_type: OrderType + type: OrderType @define(kw_only=True) diff --git a/src/pywmapi/profile/api.py b/src/pywmapi/profile/api.py index 3ed7292..dce0a01 100644 --- a/src/pywmapi/profile/api.py +++ b/src/pywmapi/profile/api.py @@ -22,7 +22,7 @@ def get_current_user(sess: Session) -> User: User: user """ res = requests.get( - API_BASE_URL + f"/profile", + API_BASE_URL + f"/user", **sess.to_header_dict(), ) check_wm_response(res) @@ -39,10 +39,10 @@ def get_profile_by_username(username: str) -> Profile: Profile: user profile """ res = requests.get( - API_BASE_URL + f"/profile/{username}", + API_BASE_URL + f"/user/{username}", ) check_wm_response(res) - return Profile.from_dict(res.json()["payload"]["profile"]) + return Profile.from_dict(res.json()["data"]) def set_profile_status(sess: Session, status: ProfileStatus) -> None: diff --git a/src/pywmapi/profile/models.py b/src/pywmapi/profile/models.py index bdbe485..665ff26 100644 --- a/src/pywmapi/profile/models.py +++ b/src/pywmapi/profile/models.py @@ -15,30 +15,49 @@ class Profile(ModelBase): @define class Achievement: - name: str + id: str icon: str description: str - exposed: bool # might be always `patreon` type: str id: str """User ID.""" - ingame_name: str - """In-game name.""" + slug: str status: ProfileStatus """Wfm status.""" + slug: str + icon: str + thumb: str platform: Platform - region: str + locale: str banned: bool avatar: str - last_seen: datetime + lastSeen: datetime reputation: int about: str - """User's about-me section. Rendered as HTML.""" - about_raw: str - """User's about-me section. Raw text.""" own_profile: bool - achievements: List[Achievement] - ban_reason: Optional[str] = None + achievementShowcase: Optional[Achievement] + banMessage: Optional[str] = None background: Optional[str] = None + + @classmethod + def from_dict(cls, data: dict) -> "Profile": + return cls( + id=data.get("id"), + slug=data.get("slug"), + status=ProfileStatus(data.get("status")), + icon=data.get("icon"), + thumb=data.get("thumb"), + platform=Platform(data.get("platform")), + locale=data.get("locale"), + banned=data.get("banned", False), + avatar=data.get("avatar"), + lastSeen=datetime.fromisoformat(data.get("lastSeen").replace("Z", "+00:00")), + reputation=data.get("reputation"), + about=data.get("about"), + own_profile=data.get("ownProfile", False), + achievementShowcase=data.get("achievementShowcase"), + banMessage=data.get("banMessage"), + background=data.get("background"), + ) diff --git a/tests/test_orders_api.py b/tests/test_orders_api.py index 0d40b4f..eecbceb 100644 --- a/tests/test_orders_api.py +++ b/tests/test_orders_api.py @@ -7,8 +7,12 @@ def test_get_orders(): - get_orders("mirage_prime_systems", include=IncludeOption.item) - get_orders("heavy_trauma", include=IncludeOption.item) + result1 = get_orders("mirage_prime_systems") + assert isinstance(result1, list) + assert len(result1) > 0 + result2 = get_orders("heavy_trauma") + assert isinstance(result2, list) + assert len(result2) > 0 @pytest.mark.skipif(get_test_signin_dict() is None, reason="No test account.") diff --git a/tests/test_profile_api.py b/tests/test_profile_api.py index 387582c..8e1df78 100644 --- a/tests/test_profile_api.py +++ b/tests/test_profile_api.py @@ -7,7 +7,7 @@ def test_get_profile_by_username(): - get_profile_by_username("AyajiLin") + get_profile_by_username("megan") @pytest.mark.skipif(get_test_signin_dict() is None, reason="No test account.")