Last active
February 3, 2023 17:38
-
-
Save aalmiray/b4c3b7f3db7b5d253814169d20d8fe26 to your computer and use it in GitHub Desktop.
Post to Mastodon
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
///usr/bin/env jbang "$0" "$@" ; exit $? | |
//JAVA 11+ | |
//REPOS jitpack | |
//REPOS mavencentral | |
//DEPS com.github.jreleaser.jreleaser:jreleaser-mastodon-java-sdk:main-a330172c0d-1 | |
//DEPS org.slf4j:slf4j-simple:2.0.6 | |
import org.jreleaser.sdk.mastodon.MastodonSdk; | |
import org.jreleaser.logging.SimpleJReleaserLoggerAdapter; | |
import java.util.List; | |
import static org.jreleaser.util.StringUtils.requireNonBlank; | |
import static org.jreleaser.util.ObjectUtils.requireNonEmpty; | |
/* | |
* Post a message to a Mastodon instance. | |
* | |
* Requires the following environment variables: | |
* - MSTD_HOST, ie https://mastodon.social | |
* - MSTD_TOKEN, API access token | |
* | |
* At leat one argument must be supplied. | |
*/ | |
public class mastodon { | |
public static void main(String... args) throws Exception { | |
MastodonSdk.builder(new SimpleJReleaserLoggerAdapter()) | |
.host(requireNonBlank(System.getenv().get("MSTD_HOST"), "host")) | |
.accessToken(requireNonBlank(System.getenv().get("MSTD_TOKEN"), "token")) | |
.connectTimeout(60_000) | |
.readTimeout(20_000) | |
.build() | |
.toot(List.of(requireNonEmpty(args, "Must supply at least 1 arg"))); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment