File: __init__.py

package info (click to toggle)
python-xbox-webapi 2.1.0-1.2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 2,900 kB
  • sloc: python: 4,973; makefile: 79
file content (70 lines) | stat: -rw-r--r-- 2,337 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
"""
EPLists - Mainly used for XBL Pins
"""
from xbox.webapi.api.provider.baseprovider import BaseProvider
from xbox.webapi.api.provider.lists.models import ListMetadata, ListsResponse


class ListsProvider(BaseProvider):
    LISTS_URL = "https://eplists.xboxlive.com"
    HEADERS_LISTS = {"Content-Type": "application/json", "x-xbl-contract-version": "2"}

    SEPERATOR = "."

    async def remove_items(
        self, xuid: str, post_body: dict, listname: str = "XBLPins", **kwargs
    ) -> ListMetadata:
        """
        Remove items from specific list, defaults to "XBLPins"

        Args:
            xuid (str/int): Xbox User Id
            listname (str): Name of list to edit

        Returns:
            :class:`ListMetadata`: List Metadata Response
        """
        url = self.LISTS_URL + f"/users/xuid({xuid})/lists/PINS/{listname}"
        resp = await self.client.session.delete(
            url, json=post_body, headers=self.HEADERS_LISTS, **kwargs
        )
        resp.raise_for_status()
        return ListMetadata(**resp.json())

    async def get_items(
        self, xuid: str, listname: str = "XBLPins", **kwargs
    ) -> ListsResponse:
        """
        Get items from specific list, defaults to "XBLPins"

        Args:
            xuid (str/int): Xbox User Id
            listname (str): Name of list to edit

        Returns:
            :class:`ListsResponse`: List Response
        """
        url = self.LISTS_URL + f"/users/xuid({xuid})/lists/PINS/{listname}"
        resp = await self.client.session.get(url, headers=self.HEADERS_LISTS, **kwargs)
        resp.raise_for_status()
        return ListsResponse(**resp.json())

    async def insert_items(
        self, xuid: str, post_body: dict, listname: str = "XBLPins", **kwargs
    ) -> ListMetadata:
        """
        Insert items to specific list, defaults to "XBLPins"

        Args:
            xuid (str/int): Xbox User Id
            listname (str): Name of list to edit

        Returns:
            :class:`ListMetadata`: List Metadata Response
        """
        url = self.LISTS_URL + f"/users/xuid({xuid})/lists/PINS/{listname}"
        resp = await self.client.session.post(
            url, json=post_body, headers=self.HEADERS_LISTS, **kwargs
        )
        resp.raise_for_status()
        return ListMetadata(**resp.json())