Skip to content

Added getting of the latest project version #9

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

Merged
merged 1 commit into from
Jun 10, 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
11 changes: 1 addition & 10 deletions docs/readme.md
Original file line number Diff line number Diff line change
@@ -1,15 +1,6 @@
# Modrinth.py
Interact with Modrinth's Labrinth API through Python.

## API Version

Service | Version
----------------------|----------
Modrinth.py version | v0.1.3
Labrinth API version | v2.4.4

*Modrinth.py works on the latest Labrinth version!*

## To-do
- [x] Search for projects
- [x] (Un)follow projects
Expand All @@ -26,7 +17,7 @@ Interact with Modrinth's Labrinth API through Python.
- [ ] Upload files to version
- [ ] Get a version from `sha1` or `sha512`
- [ ] Delete a file from its hash (DELETE requests to `/version_file`)
- [ ] Get latest project(s) version(s)
- [x] Get latest project(s) version(s)
- [ ] Get project version from hash
- [x] Read user(s) data
- [ ] Delete and modify user data
Expand Down
14 changes: 13 additions & 1 deletion modrinth/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,12 @@ def unfollow(self, user: Users.AuthenticatedUser):
headers = {'Authorization': user.token}
requests.delete(url, headers=headers)

def getLatestVersion(self):
'''
Gets the latest version for the current project.
'''
return Versions.getLatestVersion(self)

def getVersion(self, version):
'''
Shorthand for Versions.ModrinthVersion with no project argument.
Expand All @@ -160,7 +166,7 @@ def getAllVersions(self):
'''
Get Versions.getVersions() for all versions found for the project.
'''
return Versions.getVersions(self.versions)
return Versions.getVersions(self, self.versions)

def getProjects(ids: list) -> list:
'''
Expand Down Expand Up @@ -317,3 +323,9 @@ def getVersions(project: Projects.ModrinthProject, ids: list) -> list:
Get a list of versions, given a list of IDs.
'''
return [Versions.ModrinthVersion(project, id) for id in ids]

def getLatestVersion(project: Projects.ModrinthProject) -> ModrinthVersion:
'''
Gets the latest version, given a project.
'''
return project.getAllVersions()[-1]