diff --git a/USAGE.md b/USAGE.md index bcbecc0b0..b74d4d6d3 100644 --- a/USAGE.md +++ b/USAGE.md @@ -88,6 +88,9 @@ val accessToken = client.oauth.getAccessToken( ) ``` +If your app is a command line application and is not meant for a human user to login, you can use the access token +generated from your Mastodon account. You find it under "Development > Your application > Access Token". + ## Get Home Timeline Using the received access token, we can retrieve statuses from the user's home timeline and display them. @@ -113,6 +116,17 @@ result.part.sortedBy { it.createdAt }.forEach { } ``` +__Java__ + +```java +MastodonClient client = new MastodonClient.Builder(instanceHostname).accessToken(accessToken).build(); +Pageable timeline = client.timelines().getHomeTimeline(new Range(null, null, 5)).execute(); + +timeline.getPart().forEach(status -> { + System.out.println(status.getContent()); +}); +``` + ## Post a status We can also post a status as the user. @@ -136,6 +150,19 @@ try { } ``` +__Java__ + +```java +MastodonRequest request = client.statuses() + .postStatus("Hello World", + null, + null, + false, + null, + Status.Visibility.Unlisted); + Status status = request.execute(); +``` + ## Get Raw JSON The examples in this section demonstrate, how raw JSON responses can be processed by using the `doOnJson` method. `doOnJson`is invoked for every single JSON object that is returned. diff --git a/bigbone-rx/src/main/kotlin/social/bigbone/rx/RxStatusMethods.kt b/bigbone-rx/src/main/kotlin/social/bigbone/rx/RxStatusMethods.kt index a9dc4c23f..d9929eb7d 100644 --- a/bigbone-rx/src/main/kotlin/social/bigbone/rx/RxStatusMethods.kt +++ b/bigbone-rx/src/main/kotlin/social/bigbone/rx/RxStatusMethods.kt @@ -1,14 +1,14 @@ package social.bigbone.rx -import io.reactivex.rxjava3.core.Completable import io.reactivex.rxjava3.core.Single import social.bigbone.MastodonClient import social.bigbone.api.Pageable import social.bigbone.api.Range import social.bigbone.api.entity.Account import social.bigbone.api.entity.Context -import social.bigbone.api.entity.PreviewCard +import social.bigbone.api.entity.ScheduledStatus import social.bigbone.api.entity.Status +import social.bigbone.api.entity.Translation import social.bigbone.api.method.StatusMethods /** @@ -41,17 +41,19 @@ class RxStatusMethods(client: MastodonClient) { } } - fun getCard(statusId: String): Single { + @JvmOverloads + fun translateStatus(statusId: String, language: String? = null): Single { return Single.create { try { - val context = statusMethods.getCard(statusId) - it.onSuccess(context.execute()) + val translation = statusMethods.translateStatus(statusId, language) + it.onSuccess(translation.execute()) } catch (e: Throwable) { it.onError(e) } } } + @JvmOverloads fun getRebloggedBy(statusId: String, range: Range = Range()): Single> { return Single.create { try { @@ -63,7 +65,7 @@ class RxStatusMethods(client: MastodonClient) { } } - // GET /api/v1/favourited_by + @JvmOverloads fun getFavouritedBy(statusId: String, range: Range = Range()): Single> { return Single.create { try { @@ -75,17 +77,19 @@ class RxStatusMethods(client: MastodonClient) { } } + @JvmOverloads fun postStatus( status: String, inReplyToId: String? = null, mediaIds: List? = null, sensitive: Boolean = false, spoilerText: String? = null, - visibility: Status.Visibility = Status.Visibility.Public + visibility: Status.Visibility = Status.Visibility.Public, + language: String? = null ): Single { return Single.create { try { - val result = statusMethods.postStatus(status, inReplyToId, mediaIds, sensitive, spoilerText, visibility) + val result = statusMethods.postStatus(status, inReplyToId, mediaIds, sensitive, spoilerText, visibility, language) it.onSuccess(result.execute()) } catch (e: Throwable) { it.onError(e) @@ -93,21 +97,113 @@ class RxStatusMethods(client: MastodonClient) { } } - fun deleteStatus(statusId: String): Completable { - return Completable.create { + @JvmOverloads + fun postPoll( + status: String, + pollOptions: List, + pollExpiresIn: Int, + pollMultiple: Boolean = false, + pollHideTotals: Boolean = false, + inReplyToId: String? = null, + sensitive: Boolean = false, + spoilerText: String? = null, + visibility: Status.Visibility = Status.Visibility.Public, + language: String? = null + ): Single { + return Single.create { try { - statusMethods.deleteStatus(statusId) - it.onComplete() + val result = statusMethods.postPoll( + status, + pollOptions, + pollExpiresIn, + pollMultiple, + pollHideTotals, + inReplyToId, + sensitive, + spoilerText, + visibility, + language + ) + it.onSuccess(result.execute()) } catch (e: Throwable) { it.onError(e) } } } - fun reblogStatus(statusId: String): Single { + @JvmOverloads + fun scheduleStatus( + status: String, + inReplyToId: String? = null, + mediaIds: List? = null, + sensitive: Boolean = false, + spoilerText: String? = null, + visibility: Status.Visibility = Status.Visibility.Public, + language: String? = null, + scheduledAt: String + ): Single { return Single.create { try { - val status = statusMethods.reblogStatus(statusId) + val result = statusMethods.scheduleStatus(status, inReplyToId, mediaIds, sensitive, spoilerText, visibility, language, scheduledAt) + it.onSuccess(result.execute()) + } catch (e: Throwable) { + it.onError(e) + } + } + } + + @JvmOverloads + fun schedulePoll( + status: String, + pollOptions: List, + pollExpiresIn: Int, + pollMultiple: Boolean = false, + pollHideTotals: Boolean = false, + inReplyToId: String? = null, + sensitive: Boolean = false, + spoilerText: String? = null, + visibility: Status.Visibility = Status.Visibility.Public, + language: String? = null, + scheduledAt: String + ): Single { + return Single.create { + try { + val result = statusMethods.schedulePoll( + status, + pollOptions, + pollExpiresIn, + pollMultiple, + pollHideTotals, + inReplyToId, + sensitive, + spoilerText, + visibility, + language, + scheduledAt + ) + it.onSuccess(result.execute()) + } catch (e: Throwable) { + it.onError(e) + } + } + } + + fun deleteStatus(statusId: String): Single { + return Single.create { + try { + val status = statusMethods.deleteStatus(statusId) + it.onSuccess(status.execute()) + } catch (e: Throwable) { + it.onError(e) + } + } + } + + @JvmOverloads + fun reblogStatus(statusId: String, visibility: Status.Visibility = Status.Visibility.Public): Single { + return Single.create { + try { + val status = statusMethods.reblogStatus(statusId, visibility) it.onSuccess(status.execute()) } catch (e: Throwable) { it.onError(e) @@ -147,4 +243,70 @@ class RxStatusMethods(client: MastodonClient) { } } } + + fun bookmarkStatus(statusId: String): Single { + return Single.create { + try { + val status = statusMethods.bookmarkStatus(statusId) + it.onSuccess(status.execute()) + } catch (e: Throwable) { + it.onError(e) + } + } + } + + fun unbookmarkStatus(statusId: String): Single { + return Single.create { + try { + val status = statusMethods.unbookmarkStatus(statusId) + it.onSuccess(status.execute()) + } catch (e: Throwable) { + it.onError(e) + } + } + } + + fun muteConversation(statusId: String): Single { + return Single.create { + try { + val status = statusMethods.muteConversation(statusId) + it.onSuccess(status.execute()) + } catch (e: Throwable) { + it.onError(e) + } + } + } + + fun unmuteConversation(statusId: String): Single { + return Single.create { + try { + val status = statusMethods.unmuteConversation(statusId) + it.onSuccess(status.execute()) + } catch (e: Throwable) { + it.onError(e) + } + } + } + + fun pinStatus(statusId: String): Single { + return Single.create { + try { + val status = statusMethods.pinStatus(statusId) + it.onSuccess(status.execute()) + } catch (e: Throwable) { + it.onError(e) + } + } + } + + fun unpinStatus(statusId: String): Single { + return Single.create { + try { + val status = statusMethods.unpinStatus(statusId) + it.onSuccess(status.execute()) + } catch (e: Throwable) { + it.onError(e) + } + } + } } diff --git a/bigbone/src/main/kotlin/social/bigbone/api/entity/Poll.kt b/bigbone/src/main/kotlin/social/bigbone/api/entity/Poll.kt new file mode 100644 index 000000000..b6d4a5c28 --- /dev/null +++ b/bigbone/src/main/kotlin/social/bigbone/api/entity/Poll.kt @@ -0,0 +1,88 @@ +package social.bigbone.api.entity + +import com.google.gson.annotations.SerializedName + +/** + * Represents a poll attached to a status. + * @see Mastodon API Poll + */ +data class Poll( + /** + * The ID of the poll in the database. + */ + @SerializedName("id") + val id: String = "", + + /** + * When the poll ends. ISO 8601 Datetime string, or null if the poll does not end. + */ + @SerializedName("expires_at") + val expiresAt: String? = null, + + /** + * Is the poll currently expired? + */ + @SerializedName("expired") + val expired: Boolean = false, + + /** + * Does the poll allow multiple-choice answers? + */ + @SerializedName("multiple") + val multiple: Boolean = false, + + /** + * How many votes have been received. + */ + @SerializedName("votes_count") + val votesCount: Int = 0, + + /** + * How many unique accounts have voted on a multiple-choice poll; integer, or null if [multiple] is false. + */ + @SerializedName("voters_count") + val votersCount: Int? = null, + + /** + * Possible answers for the poll. + */ + @SerializedName("options") + val options: List