Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature/#314/gith…
Browse files Browse the repository at this point in the history
…ub-action-release-workflow
  • Loading branch information
PattaFeuFeu committed Nov 26, 2023
2 parents 2450370 + 3b8ee0e commit 06a41c2
Show file tree
Hide file tree
Showing 77 changed files with 2,877 additions and 50 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,22 @@ class RxNotificationMethods(client: MastodonClient) {

private val notificationMethods = NotificationMethods(client)

/**
* Notifications concerning the user.
* @param includeTypes Types to include in the results.
* @param excludeTypes Types to exclude from the results.
* @param accountId Return only notifications received from the specified account.
* @param range optional Range for the pageable return value.
* @see <a href="https://docs.joinmastodon.org/methods/notifications/#get">Mastodon API documentation: methods/notifications/#get</a>
*/
@JvmOverloads
fun getAllNotifications(
includeTypes: List<Notification.NotificationType>? = null,
excludeTypes: List<Notification.NotificationType>? = null,
accountId: String? = null,
range: Range = Range()
): Single<Pageable<Notification>> = Single.fromCallable {
notificationMethods.getAllNotifications(excludeTypes, range).execute()
notificationMethods.getAllNotifications(includeTypes, excludeTypes, accountId, range).execute()
}

fun getNotification(id: String): Single<Notification> = Single.fromCallable {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package social.bigbone.rx.admin

import io.reactivex.rxjava3.core.Single
import social.bigbone.MastodonClient
import social.bigbone.api.entity.admin.AdminMeasure
import social.bigbone.api.entity.admin.AdminMeasure.Key
import social.bigbone.api.method.admin.AdminMeasureMethods
import social.bigbone.api.method.admin.RequestMeasure
import java.time.Instant

/**
* Reactive implementation of [AdminMeasureMethods].
*
* Obtain quantitative metrics about the server.
* @see <a href="https://docs.joinmastodon.org/methods/admin/measures/">Mastodon admin/measures API methods</a>
*/
class RxAdminMeasuresMethods(client: MastodonClient) {

private val adminMeasureMethods = AdminMeasureMethods(client)

/**
* Obtain statistical measures for your server.
*
* @param measures Request specific measures. Uses helper wrapper [RequestMeasure] to ensure that required fields are set for any given [Key].
* @param startAt The start date for the time period. If a time is provided, it will be ignored.
* @param endAt The end date for the time period. If a time is provided, it will be ignored.
*
* @see <a href="https://docs.joinmastodon.org/methods/admin/measures/#get">Mastodon API documentation: admin/measures/#get</a>
*/
fun getMeasurableDate(
measures: List<RequestMeasure>,
startAt: Instant,
endAt: Instant
): Single<List<AdminMeasure>> = Single.fromCallable {
adminMeasureMethods.getMeasurableData(
measures = measures,
startAt = startAt,
endAt = endAt
).execute()
}
}
22 changes: 15 additions & 7 deletions bigbone/src/main/kotlin/social/bigbone/MastodonClient.kt
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import social.bigbone.api.method.StreamingMethods
import social.bigbone.api.method.SuggestionMethods
import social.bigbone.api.method.TagMethods
import social.bigbone.api.method.TimelineMethods
import social.bigbone.api.method.admin.AdminMeasureMethods
import social.bigbone.api.method.admin.AdminRetentionMethods
import social.bigbone.extension.emptyRequestBody
import social.bigbone.nodeinfo.NodeInfoClient
Expand Down Expand Up @@ -76,6 +77,13 @@ private constructor(
@get:JvmName("accounts")
val accounts: AccountMethods by lazy { AccountMethods(this) }

/**
* Access API methods under the "admin/measures" endpoint.
*/
@Suppress("unused") // public API
@get:JvmName("adminMeasures")
val adminMeasures: AdminMeasureMethods by lazy { AdminMeasureMethods(this) }

/**
* Access API methods under the "admin/retention" endpoint.
*/
Expand Down Expand Up @@ -244,6 +252,13 @@ private constructor(
@get:JvmName("preferences")
val preferences: PreferenceMethods by lazy { PreferenceMethods(this) }

/**
* Access API methods under "push" endpoint.
*/
@Suppress("unused") // public API
@get:JvmName("pushNotifications")
val pushNotifications: PushNotificationMethods by lazy { PushNotificationMethods(this) }

/**
* Access API methods under the "reports" endpoint.
*/
Expand Down Expand Up @@ -293,13 +308,6 @@ private constructor(
@get:JvmName("timelines")
val timelines: TimelineMethods by lazy { TimelineMethods(this) }

/**
* Access API methods under "push" endpoint.
*/
@Suppress("unused") // public API
@get:JvmName("pushNotifications")
val pushNotifications: PushNotificationMethods by lazy { PushNotificationMethods(this) }

/**
* Specifies the HTTP methods / HTTP verb that can be used by this class.
*/
Expand Down
38 changes: 25 additions & 13 deletions bigbone/src/main/kotlin/social/bigbone/Parameters.kt
Original file line number Diff line number Diff line change
@@ -1,15 +1,18 @@
package social.bigbone

import java.net.URLEncoder
import java.util.ArrayList
import java.util.UUID

typealias Key = String
typealias Value = String

/**
* Parameters holds a list of String key/value pairs that can be used as query part of a URL, or in the body of a request.
* Parameters holds a mapping of [Key] to [Value]s that can be used as query part of a URL, or in the body of a request.
* Add new pairs using one of the available append() functions.
*/
class Parameters {
private val parameterList = ArrayList<Pair<String, String>>()

internal val parameters: MutableMap<Key, MutableList<Value>> = mutableMapOf()

/**
* Appends a new key/value pair with a String value.
Expand All @@ -18,7 +21,7 @@ class Parameters {
* @return this Parameters instance
*/
fun append(key: String, value: String): Parameters {
parameterList.add(Pair(key, value))
parameters.getOrPut(key, ::mutableListOf).add(value)
return this
}

Expand Down Expand Up @@ -77,10 +80,15 @@ class Parameters {
* Converts this Parameters instance into a query string.
* @return String, formatted like: "key1=value1&key2=value2&..."
*/
fun toQuery(): String =
parameterList.joinToString(separator = "&") {
"${it.first}=${URLEncoder.encode(it.second, "utf-8")}"
}
fun toQuery(): String {
return parameters
.map { (key, values) ->
values.joinToString(separator = "&") { value ->
"$key=${URLEncoder.encode(value, "utf-8")}"
}
}
.joinToString(separator = "&")
}

/**
* Generates a UUID string for this parameter list. UUIDs returned for different Parameters instances should be
Expand All @@ -89,10 +97,14 @@ class Parameters {
* @return Type 3 UUID as a String.
*/
fun uuid(): String {
val parameterString = parameterList
.sortedWith(compareBy { it.first })
.joinToString { "${it.first}${it.second}" }
val uuid = UUID.nameUUIDFromBytes(parameterString.toByteArray())
return uuid.toString()
return UUID
.nameUUIDFromBytes(
parameters
.entries
.sortedWith(compareBy { (key, _) -> key })
.joinToString { (key, value) -> "$key$value" }
.toByteArray()
)
.toString()
}
}
33 changes: 28 additions & 5 deletions bigbone/src/main/kotlin/social/bigbone/api/entity/Notification.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package social.bigbone.api.entity

import kotlinx.serialization.ExperimentalSerializationApi
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import social.bigbone.DateTimeSerializer
Expand All @@ -22,7 +23,7 @@ data class Notification(
* The type of event that resulted in the notification.
*/
@SerialName("type")
val type: NotificationType = NotificationType.MENTION,
val type: NotificationType? = null,

/**
* The timestamp of the notification.
Expand Down Expand Up @@ -54,16 +55,38 @@ data class Notification(
*/
@Serializable
enum class NotificationType {

@SerialName("admin.report")
ADMIN_REPORT,

@SerialName("admin.sign_up")
ADMIN_SIGN_UP,

@SerialName("favourite")
FAVOURITE,

@SerialName("follow")
FOLLOW,

@SerialName("follow_request")
FOLLOW_REQUEST,

@SerialName("mention")
MENTION,

@SerialName("poll")
POLL,

@SerialName("reblog")
REBLOG,

@SerialName("favourite")
FAVOURITE,
@SerialName("status")
STATUS,

@SerialName("follow")
FOLLOW
@SerialName("update")
UPDATE;

@OptIn(ExperimentalSerializationApi::class)
val apiName: String get() = serializer().descriptor.getElementName(ordinal)
}
}
Loading

0 comments on commit 06a41c2

Please sign in to comment.