Skip to content

Commit

Permalink
fix non-backward comptaible type Union and port datastore changes to …
Browse files Browse the repository at this point in the history
…async
  • Loading branch information
treeben77 committed Dec 7, 2024
1 parent e17dcb4 commit 85430be
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 27 deletions.
2 changes: 1 addition & 1 deletion rblxopencloud/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ def list_versions(
)

def get_version(
self, key: str, version: str | datetime.datetime
self, key: str, version: Union[str, datetime.datetime]
) -> tuple[Union[str, dict, list, int, float], EntryInfo]:
"""
Gets the value of a key at a specific version ID.
Expand Down
42 changes: 16 additions & 26 deletions rblxopencloudasync/datastore.py
Original file line number Diff line number Diff line change
Expand Up @@ -524,7 +524,7 @@ async def list_versions(
)

async def get_version(
self, key: str, version: str
self, key: str, version: Union[str, datetime.datetime]
) -> tuple[Union[str, dict, list, int, float], EntryInfo]:
"""
Gets the value of a key at a specific version ID.
Expand All @@ -542,17 +542,15 @@ async def get_version(
except ValueError:
raise ValueError("'scope/key' syntax expected for key.")

status_code, data, headers = await send_request(
if type(version) == datetime.datetime:
time = version.astimezone(tz=datetime.timezone.utc)
version = f"latest:{time.isoformat('T').split('.')[0] + 'Z'}"

status_code, data, _ = await send_request(
"GET",
f"datastores/v1/universes/{self.experience.id}/standard-datastores\
/datastore/entries/entry/versions/version",
f"/universes/{self.experience.id}/\
data-stores/{self.name}/entries/{key}@{version}",
authorization=self.__api_key,
params={
"datastoreName": self.name,
"scope": scope,
"entryKey": key,
"versionId": version,
},
expected_status=[200, 400],
)

Expand All @@ -562,22 +560,14 @@ async def get_version(
else:
raise HttpException(status_code, data)

if headers.get("roblox-entry-attributes"):
metadata = json.loads(headers["roblox-entry-attributes"])
else:
metadata = {}

if headers.get("roblox-entry-userids"):
userids = json.loads(headers["roblox-entry-userids"])
else:
userids = []

return data, EntryInfo(
headers["roblox-entry-version"],
headers["roblox-entry-created-time"],
headers["roblox-entry-version-created-time"],
userids,
metadata,
return data["value"], EntryInfo(
data["revisionId"],
data["createTime"],
data["revisionCreateTime"],
users=[
int(user_id.split("/")[1]) for user_id in data.get("users", [])
],
metadata=data["attributes"],
)


Expand Down
26 changes: 26 additions & 0 deletions rblxopencloudasync/experience.py
Original file line number Diff line number Diff line change
Expand Up @@ -983,6 +983,32 @@ async def list_datastores(
scope,
)

async def snapshot_datastores(self) -> tuple[bool, datetime]:
"""
Takes a new snapshot of the data stores in an experience. This means \
that all current versions are guaranteed to be available for at least \
30 days.
Only one snapshot may be taken each UTC day and returns the last time \
a snapshot was created if one has already been made today.
Returns:
A tuple with a boolean of whether a new snapshot was taken and \
the time of the last snapshot.
"""

_, data, _ = await send_request(
"POST",
f"/universes/{self.id}/data-stores:snapshot",
authorization=self.__api_key,
expected_status=[200],
json={},
)

return data["newSnapshotTaken"], parser.parse(
data["latestSnapshotTime"]
)

def get_sorted_map(self, name: str) -> SortedMap:
"""
Creates a [`SortedMap`][rblxopencloud.SortedMap] with \
Expand Down

0 comments on commit 85430be

Please sign in to comment.