Skip to content

Commit

Permalink
Merge branch 'master' into bump-kotlin-version-to-1.8
Browse files Browse the repository at this point in the history
  • Loading branch information
andregasser authored Mar 1, 2023
2 parents 137986e + c5c3b81 commit 6b33942
Show file tree
Hide file tree
Showing 17 changed files with 1,164 additions and 49 deletions.
27 changes: 27 additions & 0 deletions USAGE.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -113,6 +116,17 @@ result.part.sortedBy { it.createdAt }.forEach {
}
```

__Java__

```java
MastodonClient client = new MastodonClient.Builder(instanceHostname).accessToken(accessToken).build();
Pageable<Status> 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.
Expand All @@ -136,6 +150,19 @@ try {
}
```

__Java__

```java
MastodonRequest<Status> 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.

Expand Down
190 changes: 176 additions & 14 deletions bigbone-rx/src/main/kotlin/social/bigbone/rx/RxStatusMethods.kt
Original file line number Diff line number Diff line change
@@ -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

/**
Expand Down Expand Up @@ -41,17 +41,19 @@ class RxStatusMethods(client: MastodonClient) {
}
}

fun getCard(statusId: String): Single<PreviewCard> {
@JvmOverloads
fun translateStatus(statusId: String, language: String? = null): Single<Translation> {
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<Pageable<Account>> {
return Single.create {
try {
Expand All @@ -63,7 +65,7 @@ class RxStatusMethods(client: MastodonClient) {
}
}

// GET /api/v1/favourited_by
@JvmOverloads
fun getFavouritedBy(statusId: String, range: Range = Range()): Single<Pageable<Account>> {
return Single.create {
try {
Expand All @@ -75,39 +77,133 @@ class RxStatusMethods(client: MastodonClient) {
}
}

@JvmOverloads
fun postStatus(
status: String,
inReplyToId: String? = null,
mediaIds: List<String>? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
visibility: Status.Visibility = Status.Visibility.Public
visibility: Status.Visibility = Status.Visibility.Public,
language: String? = null
): Single<Status> {
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)
}
}
}

fun deleteStatus(statusId: String): Completable {
return Completable.create {
@JvmOverloads
fun postPoll(
status: String,
pollOptions: List<String>,
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<Status> {
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<Status> {
@JvmOverloads
fun scheduleStatus(
status: String,
inReplyToId: String? = null,
mediaIds: List<String>? = null,
sensitive: Boolean = false,
spoilerText: String? = null,
visibility: Status.Visibility = Status.Visibility.Public,
language: String? = null,
scheduledAt: String
): Single<ScheduledStatus> {
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<String>,
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<ScheduledStatus> {
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<Status> {
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<Status> {
return Single.create {
try {
val status = statusMethods.reblogStatus(statusId, visibility)
it.onSuccess(status.execute())
} catch (e: Throwable) {
it.onError(e)
Expand Down Expand Up @@ -147,4 +243,70 @@ class RxStatusMethods(client: MastodonClient) {
}
}
}

fun bookmarkStatus(statusId: String): Single<Status> {
return Single.create {
try {
val status = statusMethods.bookmarkStatus(statusId)
it.onSuccess(status.execute())
} catch (e: Throwable) {
it.onError(e)
}
}
}

fun unbookmarkStatus(statusId: String): Single<Status> {
return Single.create {
try {
val status = statusMethods.unbookmarkStatus(statusId)
it.onSuccess(status.execute())
} catch (e: Throwable) {
it.onError(e)
}
}
}

fun muteConversation(statusId: String): Single<Status> {
return Single.create {
try {
val status = statusMethods.muteConversation(statusId)
it.onSuccess(status.execute())
} catch (e: Throwable) {
it.onError(e)
}
}
}

fun unmuteConversation(statusId: String): Single<Status> {
return Single.create {
try {
val status = statusMethods.unmuteConversation(statusId)
it.onSuccess(status.execute())
} catch (e: Throwable) {
it.onError(e)
}
}
}

fun pinStatus(statusId: String): Single<Status> {
return Single.create {
try {
val status = statusMethods.pinStatus(statusId)
it.onSuccess(status.execute())
} catch (e: Throwable) {
it.onError(e)
}
}
}

fun unpinStatus(statusId: String): Single<Status> {
return Single.create {
try {
val status = statusMethods.unpinStatus(statusId)
it.onSuccess(status.execute())
} catch (e: Throwable) {
it.onError(e)
}
}
}
}
88 changes: 88 additions & 0 deletions bigbone/src/main/kotlin/social/bigbone/api/entity/Poll.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,88 @@
package social.bigbone.api.entity

import com.google.gson.annotations.SerializedName

/**
* Represents a poll attached to a status.
* @see <a href="https://docs.joinmastodon.org/entities/Poll/">Mastodon API Poll</a>
*/
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<Option> = emptyList(),

/**
* Custom emoji to be used for rendering poll options.
*/
@SerializedName("emojis")
val emojis: List<CustomEmoji> = emptyList(),

/**
* When called with a user token, has the authorized user voted?
*/
@SerializedName("voted")
val voted: Boolean? = null,

/**
* When called with a user token, which options has the authorized user chosen? Contains an array of index values for [options].
*/
@SerializedName("own_votes")
val ownVotes: List<Int>? = null

) {
/**
* Possible answers for the poll.
* @see <a href="https://docs.joinmastodon.org/entities/Poll/#Option">Mastodon API Poll::Option</a>
*/
data class Option(
/**
* The text value of the poll option.
*/
@SerializedName("title")
val title: String = "",

/**
* The total number of received votes for this option; integer, or null if results are not published yet.
*/
@SerializedName("votes_count")
val votesCount: Int? = null
)
}
Loading

0 comments on commit 6b33942

Please sign in to comment.