Skip to content
This repository has been archived by the owner on Apr 21, 2024. It is now read-only.

Commit

Permalink
docs(Examples): Provide an example for the usage of the new Update-ob…
Browse files Browse the repository at this point in the history
…ject in the README and expand sourceTar and sourceTarBz2 methods descriptions on when they are available.
  • Loading branch information
Griefed committed Apr 17, 2022
1 parent 622a289 commit 9af7137
Show file tree
Hide file tree
Showing 2 changed files with 53 additions and 7 deletions.
46 changes: 45 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,10 +61,54 @@ implementation 'de.griefed:versionchecker:$VERSION'

For available versions, see the [sonatype repo](https://search.maven.org/artifact/de.griefed/versionchecker/)

# Example
# Examples

See [UpdateCheckerTests](src/test/java/de/griefed/versionchecker/UpdateCheckerTests.java)

The simplest way to acquire update information is to call `.check(...)` of your GitHub- or GitHubChecker instances with your current version.
This will return an instance of [Update](https://github.com/Griefed/VersionChecker/blob/main/src/main/java/de/griefed/versionchecker/Update.java) which contains
details about the available update. It is wrapped in an Optional, so you can conveniently check via `.isPresent()` if an update is available.

Once an instance of [Update](https://github.com/Griefed/VersionChecker/blob/main/src/main/java/de/griefed/versionchecker/Update.java) has been retrieved,
you can access information about it via any of the available methods.

Example:

```java
GitHubChecker GITHUB = new GitHubChecker("Griefed/ServerPackCreator");

Optional<Update> gitHubUpdate = GITHUB.check("3.0.1",false);
if (gitHubUpdate.isPresent()) {

// Gets the version of this update as a String.
gitHubUpdate.get().version();

// Check whether the update has a description
if (gitHubUpdate.get().description().isPresent()) {

// Get the description
gitHubUpdate.get().description().get();
}

// Get the url to the release page of this update
gitHubUpdate.get().url();

// Get the date at which this update has been released.
gitHubUpdate.get().releaseDate();

// Check if the update has any assets attached to it
if (gitHubUpdate.get().assets().isPresent()) {

// Get the available assets of this update
gitHubUpdate.get().assets().get();
}

// Get the available source-archives of this update
gitHubUpdate.get().sources();
}

```

```java
public class UpdateChecker {

Expand Down
14 changes: 8 additions & 6 deletions src/main/java/de/griefed/versionchecker/Update.java
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,9 @@ public Source sourceZip() {
}

/**
* Get the ZIP-archive-source of this update.
* Get the tar.gz-archive-source of this update.
* @author Griefed
* @return {@link Source} of {@link ArchiveType#ZIP} of this update.
* @return {@link Source} of {@link ArchiveType#TAR_GZ} of this update.
*/
public Source sourceTarGz() {
for (Source source : SOURCES) {
Expand All @@ -160,9 +160,10 @@ public Source sourceTarGz() {
}

/**
* Get the ZIP-archive-source of this update.
* Get the tar-archive-source of this update. A tar-archive is usually only available for GitLab updates. GitHub typically
* only provides zip- and tar.gz-archives.
* @author Griefed
* @return {@link Source} of {@link ArchiveType#ZIP} of this update, wrapped in an {@link Optional}.
* @return {@link Source} of {@link ArchiveType#TAR} of this update, wrapped in an {@link Optional}.
*/
public Optional<Source> sourceTar() {
for (Source source : SOURCES) {
Expand All @@ -174,9 +175,10 @@ public Optional<Source> sourceTar() {
}

/**
* Get the ZIP-archive-source of this update.
* Get the tar.bz2-archive-source of this update. A tar.bz2-archive is usually only available for GitLab updates. GitHub typically
* only provides zip- and tar.gz-archives.
* @author Griefed
* @return {@link Source} of {@link ArchiveType#ZIP} of this update, wrapped in an {@link Optional}.
* @return {@link Source} of {@link ArchiveType#TAR_BZ2} of this update, wrapped in an {@link Optional}.
*/
public Optional<Source> sourceTarBz2() {
for (Source source : SOURCES) {
Expand Down

0 comments on commit 9af7137

Please sign in to comment.