Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Support for Inventory API #11

Merged
merged 7 commits into from
Sep 27, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions docs/source/exceptions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,12 @@ Exceptions

The api key is invalid or doesn't have sufficent permissions to do the requested task.

.. exception:: PermissionDenied()

The client is not allowed to do the requested permissions. This is only returned in instances were the problem is usually not the API key, for example trying to retrieve a private inventory.

.. versionadded:: 1.5

.. exception:: NotFound()

An item in the request, such as a ``datastore``, ``key``, ``version`` or ``place`` was not found.
Expand Down
280 changes: 279 additions & 1 deletion docs/source/user.rst
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,39 @@ User

For OAuth2 applications, please read `this post by Hooksmith <https://devforum.roblox.com/t/public-beta-building-your-applications-with-oauth-20/2401354/36>`__.

.. method:: list_inventory(limit=None, only_collectibles=False, assets=False, badges=False, game_passes=False, private_servers=False)

Interates :class:`rblx-open-cloud.InventoryItem` for items in the user's inventory. If ``only_collectibles``, ``assets``, ``badges``, ``game_passes``, and ``private_servers`` are ``False``, then all inventory items are returned.

The example below would iterate through every item in the user's inventory.

.. code:: python

for item in experience.list_inventory():
print(item)

The ``user.inventory-item:read`` scope is required if authorized via `OAuth2 </oauth2>`__.

.. versionadded:: 1.5

:param Optional[int] limit: The maximum number of inventory items to iterate. This can be ``None`` to return all items.
:param Optional[bool] only_collectibles: Wether the only inventory assets iterated are collectibles (limited items).
:param Optional[Union[list[InventoryAssetType], list[int], bool]] assets: If this is ``True``, then it will return all assets, if it is a list of IDs, it will only return assets with the provided IDs, and if it is a list of :class:`rblx-open-cloud.InventoryAssetType` then it will only return assets of these types.
:param Optional[Union[list[int], bool]] badges: If this is ``True``, then it will return all badges, but if it is a list of IDs, it will only return badges with the provided IDs.
:param Optional[Union[list[int], bool]] game_passes: If this is ``True``, then it will return all game passes, but if it is a list of IDs, it will only return game passes with the provided IDs.
:param Optional[Union[list[int], bool]] private_servers: If this is ``True``, then it will return all private servers, but if it is a list of IDs, it will only return private servers with the provided IDs.

:returns: Iterable[Union[:class:`rblx-open-cloud.InventoryAsset`, :class:`rblx-open-cloud.InventoryBadge`, :class:`rblx-open-cloud.InventoryGamePass`, :class:`rblx-open-cloud.InventoryPrivateServer`]]
:raises rblx-open-cloud.InvalidKey: The token is invalid or doesn't have sufficent permissions to list data stores.
:raises rblx-open-cloud.PermissionDenied: The user's inventory is not public.
:raises rblx-open-cloud.RateLimited: You're being rate limited by Roblox. Try again in a minute.
:raises rblx-open-cloud.ServiceUnavailable: Roblox's services as currently experiencing downtime.
:raises rblx-open-cloud.rblx_opencloudException: Roblox's response was unexpected.

.. note::

You can access anyone's inventory if it is public. Otherwise, you must use OAuth2 to obtain consent.

.. method:: list_groups(limit=None)

Interates :class:`rblx-open-cloud.GroupMember` for each group the user is in. The API key doesn't need to belong to the user you're querying.
Expand All @@ -162,4 +195,249 @@ User
:raises rblx-open-cloud.NotFound: The user could not be found.
:raises rblx-open-cloud.RateLimited: You're being rate limited by Roblox. Try again in a minute.
:raises rblx-open-cloud.ServiceUnavailable: Roblox's services as currently experiencing downtime.
:raises rblx-open-cloud.rblx_opencloudException: Roblox's response was unexpected.
:raises rblx-open-cloud.rblx_opencloudException: Roblox's response was unexpected.

.. class:: InventoryItem()

Represents an inventory item.

.. versionadded:: 1.5

.. warning::

This class is not designed to be created by users. It is inherited by :class:`rblx-open-cloud.InventoryAsset`, :class:`rblx-open-cloud.InventoryBadge`, :class:`rblx-open-cloud.InventoryGamePass`, and :class:`rblx-open-cloud.InventoryPrivateServer`.

.. attribute:: id

The item's ID

:type: int

.. class:: InventoryAsset()

Represents an asset in the user's inventory.

.. versionadded:: 1.5

.. warning::

This class is not designed to be created by users. It is returned by :meth:`User.list_inventory`.

.. attribute:: id

The asset's ID

:type: int

.. attribute:: type

The item asset type.

:type: :class:`rblx-open-cloud.InventoryAssetType`

.. attribute:: instance_id

A unique ID that identifies the specific "copy" of the item.

:type: int

.. attribute:: serial_number

The serial number of a collectable.

:type: int

.. attribute:: collectable_state

Wether the collectable is in the holding period or not.

:type: Optional[InventoryItemState]

.. attribute:: collectable_item_id

The collectable's asset ID. This is not the same as :attr:`InventoryAsset.id`.

:type: Optional[str]

.. attribute:: collectable_instance_id

The collectable's instance ID. This is not the same as :attr:`InventoryAsset.instance_id`.

:type: Optional[str]

.. class:: InventoryBadge()

Represents a badge in a user's inventory.

.. versionadded:: 1.5

.. warning::

This class is not designed to be created by users. It is returned by :meth:`User.list_inventory`.

.. attribute:: id

The badge's ID

:type: int

.. class:: InventoryGamePass()

Represents a gamepass in a user's inventory.

.. versionadded:: 1.5

.. warning::

This class is not designed to be created by users. It is returned by :meth:`User.list_inventory`.

.. attribute:: id

The game pass's ID

:type: int

.. class:: InventoryPrivateServer()

Represents a private server in a user's inventory.

.. versionadded:: 1.5

.. warning::

This class is not designed to be created by users. It is returned by :meth:`User.list_inventory`.

.. attribute:: id

The private server's ID

:type: int

.. class:: InventoryAssetType()

Enum to denote what type an asset is.

.. versionadded:: 1.5

.. attribute:: Unknown

An unknown asset type (e.g. an unimplemented type)

.. attribute:: ClassicTShirt

.. attribute:: Audio

.. attribute:: Hat

.. attribute:: Model

.. attribute:: ClassicShirt

.. attribute:: ClassicPants

.. attribute:: Decal

.. attribute:: ClassicHead

.. attribute:: Face

.. attribute:: Gear

.. attribute:: Animation

.. attribute:: Torso

.. attribute:: RightArm

.. attribute:: LeftArm

.. attribute:: LeftLeg

.. attribute:: RightLeg

.. attribute:: Package

.. attribute:: Plugin

.. attribute:: MeshPart

.. attribute:: HairAccessory

.. attribute:: FaceAccessory

.. attribute:: NeckAccessory

.. attribute:: ShoulderAccessory

.. attribute:: FrontAccessory

.. attribute:: BackAccessory

.. attribute:: WaistAccessory

.. attribute:: ClimbAnimation

.. attribute:: DeathAnimation

.. attribute:: FallAnimation

.. attribute:: IdleAnimation

.. attribute:: JumpAnimation

.. attribute:: RunAnimation

.. attribute:: SwimAnimation

.. attribute:: WalkAnimation

.. attribute:: PoseAnimation

.. attribute:: EmoteAnimation

.. attribute:: Video

.. attribute:: TShirtAccessory

.. attribute:: ShirtAccessory

.. attribute:: PantsAccessory

.. attribute:: JacketAccessory

.. attribute:: SweaterAccessory

.. attribute:: ShortsAccessory

.. attribute:: LeftShoeAccessory

.. attribute:: RightShoeAccessory

.. attribute:: DressSkirtAccessory

.. attribute:: EyebrowAccessory

.. attribute:: EyelashAccessory

.. attribute:: MoodAnimation

.. attribute:: DynamicHead

.. attribute:: CreatedPlace

.. attribute:: PurchasedPlace

.. class:: InventoryItemState()

Enum to denote wether a collectable is avaliable to be sold or is still in the holding period.

.. versionadded:: 1.5

.. attribute:: Unknown

The item state is currently unknown.

.. attribute:: Available

.. attribute:: Hold

4 changes: 2 additions & 2 deletions rblxopencloud/group.py
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,8 @@ def fetch_info(self) -> "Group":

self.name = data["displayName"]
self.description = data["description"]
self.created_at = datetime.datetime.fromisoformat((data["createTime"].split("Z")[0]+"0"*6)[0:26])
self.updated_at = datetime.datetime.fromisoformat((data["updateTime"].split("Z")[0]+"0"*6)[0:26])
self.created_at = datetime.datetime.fromisoformat((data["createTime"].split("Z")[0]+("." if not "." in data["createTime"] else "")+"0"*6)[0:26])
self.updated_at = datetime.datetime.fromisoformat((data["updateTime"].split("Z")[0]+("." if not "." in data["updateTime"] else "")+"0"*6)[0:26])
self.owner = User(int(data["owner"].split("/")[1]), self.__api_key) if data.get("owner") else None
self.member_count = data["memberCount"]
self.public_entry = data["publicEntryAllowed"]
Expand Down
Loading