Skip to content

Instantly share code, notes, and snippets.

@aalmiray
Last active February 3, 2023 17:38
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aalmiray/b4c3b7f3db7b5d253814169d20d8fe26 to your computer and use it in GitHub Desktop.
Save aalmiray/b4c3b7f3db7b5d253814169d20d8fe26 to your computer and use it in GitHub Desktop.
Post to Mastodon
///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