Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Create FediAPI module #5

Closed
wants to merge 12 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ plugins {
alias(libs.plugins.android.library) apply false
alias(libs.plugins.ksp) apply false
alias(libs.plugins.kotlin.android) apply false
alias(libs.plugins.kotlin.multiplatform) apply false
alias(libs.plugins.kotlin.serialization) apply false
}
34 changes: 34 additions & 0 deletions fediapi/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
plugins {
alias(libs.plugins.android.library)
alias(libs.plugins.kotlin.multiplatform)
alias(libs.plugins.kotlin.serialization)
}

android {
namespace = "xyz.wingio.fediapi"
compileSdk = 34

defaultConfig {
minSdk = 21
}
}

kotlin {
androidTarget()
jvm()

jvmToolchain(17)
explicitApi()

sourceSets {
commonMain {
dependencies {
implementation(libs.ktor.client.cio)
implementation(libs.ktor.client.content.negotiation)
implementation(libs.ktor.serialization.kotlinx.json)
api(libs.ktor.client.core)
api(libs.kotlinx.datetime)
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package xyz.wingio.fediapi

public class FediClient {
}
26 changes: 26 additions & 0 deletions fediapi/src/commonMain/kotlin/xyz/wingio/fediapi/Typealiases.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package xyz.wingio.fediapi

/**
* Represents a valid URL
*/
public typealias URL = String

/**
* Represents some valid HTML
*/
public typealias HTML = String

/**
* ISO 639 language code (Most often 2 characters)
*/
public typealias Language = String

/**
* Represents a SHA256 hash
*/
public typealias SHA256 = String

/**
* Represents a valid [BlurHash](https://github.com/woltapp/blurhash)
*/
public typealias Blurhash = String
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package xyz.wingio.fediapi.software.mastodon

public object Dummy {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.HTML
import xyz.wingio.fediapi.URL
import xyz.wingio.fediapi.software.mastodon.model.status.Status.Tag

/**
* Represents an announcement set by an administrator.
*
* @param id The ID of the announcement in the database.
* @param content The text of the announcement.
* @param startsAt When the announcement will start.
* @param endsAt When the announcement will end.
* @param published Whether the announcement is currently active.
* @param allDay Whether the announcement should start and end on dates only instead of datetimes. Will be false if there is no [startsAt] or [endsAt] time.
* @param publishedAt When the announcement was published.
* @param updatedAt When the announcement was last updated.
* @param read Whether the announcement has been read by the current user.
* @param mentions Accounts mentioned in the announcement text.
* @param statuses Statuses linked in the announcement text.
* @param tags Tags linked in the announcement text.
* @param emojis Custom emoji used in the announcement text.
* @param reactions Emoji reactions attached to the announcement.
*/
@Serializable
public data class Announcement(
val id: String,
val content: HTML,
@SerialName("starts_at") val startsAt: Instant?,
@SerialName("ends_at") val endsAt: Instant?,
val published: Boolean,
@SerialName("all_day") val allDay: Boolean,
@SerialName("publishedAt") val publishedAt: Instant,
@SerialName("updated_at") val updatedAt: Instant,
val read: Boolean? = null,
val mentions: List<Account>,
val statuses: List<Status>,
val tags: List<Tag>,
val emojis: List<CustomEmoji>,
val reactions: List<Reaction>
) {

/**
* User mentioned in an [Announcement]
*
* @param id The account ID of the mentioned user.
* @param username The username of the mentioned user.
* @param url The location of the mentioned user’s profile.
* @param acct The webfinger acct: URI of the mentioned user. Equivalent to [username] for local users, or `username@domain` for remote users.
*/
@Serializable
public data class Account(
val id: String,
val username: String,
val url: URL,
val acct: String
)

/**
* Status linked in an [Announcement]'s text
*
* @param id The ID of an attached [Status] in the database.
* @param url The URL of an attached [Status].
*/
@Serializable
public data class Status(
val id: String,
val url: URL
)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.URL

/**
* Represents an application that interfaces with the REST API to access accounts or post statuses.
*
* @param name The name of your application.
* @param website The website associated with your application.
* @param clientId Client ID key, to be used for obtaining OAuth tokens
* @param clientSecret Client secret key, to be used for obtaining OAuth tokens
* @param vapidKey Used for Push Streaming API. Returned with POST /api/v1/apps. Equivalent to WebPushSubscription#server_key and Instance#vapid_public_key
*/
@Serializable
public data class Application(
val name: String,
val website: URL? = null,
@SerialName("client_id") val clientId: String? = null,
@SerialName("client_secret") val clientSecret: String? = null,
@SerialName("vapid_key") @Deprecated("pending removal") val vapidKey: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.software.mastodon.model.status.Status

/**
* Represents the tree around a given status. Used for reconstructing threads of statuses.
*
* @param ancestors Parents in the thread.
* @param descendants Children in the thread.
*/
@Serializable
public data class Context(
val ancestors: List<Status>,
val descendants: List<Status>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.software.mastodon.model.account.Account
import xyz.wingio.fediapi.software.mastodon.model.status.Status

/**
* Represents a conversation with "direct message" visibility.
*
* @param id The ID of the conversation in the database.
* @param unread Is the conversation currently marked as unread?
* @param accounts Participants in the conversation.
* @param lastStatus The last status in the conversation.
*/
@Serializable
public data class Conversation(
val id: String,
val unread: Boolean,
val accounts: List<Account>,
@SerialName("last_status") val lastStatus: Status?
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.URL

/**
* Represents a custom emoji.
*
* @param shortcode The name of the custom emoji.
* @param url A link to the custom emoji.
* @param staticUrl A link to a static copy of the custom emoji.
* @param visibleInPicker Whether this Emoji should be visible in the picker or unlisted.
* @param category Used for sorting custom emoji in the picker.
*/
@Serializable
public data class CustomEmoji(
val shortcode: String,
val url: URL,
@SerialName("static_url") val staticUrl: URL,
@SerialName("visible_in_picker") val visibleInPicker: Boolean,
val category: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.SHA256

/**
* Represents a domain that is blocked by the instance.
*
* @param domain The domain which is blocked. This may be obfuscated or partially censored.
* @param digest The SHA256 hash digest of the domain string.
* @param severity The level to which the domain is blocked.
* @param comment An optional reason for the domain block.
*/
@Serializable
public data class DomainBlock(
val domain: String,
val digest: SHA256,
val severity: Severity,
val comment: String? = null
) {

@Serializable
public enum class Severity {
/**
* Users from this domain will be hidden from timelines, threads, and notifications (unless you follow the user).
*/
@SerialName("silence") SILENCE,

/**
* Incoming messages from this domain will be rejected and dropped entirely.
*/
@SerialName("suspend") SUSPEND
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

/**
* Represents an error message.
*
* @param error The error message.
* @param errorDescription A longer description of the error, mainly provided with the OAuth API.
*/
@Serializable
public data class Error(
val error: String,
@SerialName("error_description") val errorDescription: String? = null
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.HTML

/**
* Represents an extended description for the instance, to be shown on its about page.
*
* @param updatedAt A timestamp of when the extended description was last updated.
* @param content The rendered HTML content of the extended description.
*/
@Serializable
public data class ExtendedDescription(
@SerialName("updated_at") val updatedAt: Instant,
val content: HTML
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.software.mastodon.model.account.Account

/**
* Represents a subset of your follows who also follow some other user.
*
* @param id The ID of the [Account] in the database.
* @param accounts Accounts you follow that also follow this account.
*/
@Serializable
public data class FamiliarFollowers(
val id: String,
val accounts: List<Account>
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.URL

/**
* Represents a hashtag that is featured on a profile.
*
* @param id The internal ID of the featured tag in the database.
* @param name The name of the hashtag being featured.
* @param url A link to all statuses by a user that contain this hashtag.
* @param statusesCount The number of authored statuses containing this hashtag.
* @param lastStatusAt The timestamp of the last authored status containing this hashtag.
*/
@Serializable
public data class FeaturedTag(
val id: String,
val name: String,
val url: URL,
@SerialName("statuses_count") val statusesCount: Int,
@SerialName("last_status_at") val lastStatusAt: Instant
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package xyz.wingio.fediapi.software.mastodon.model

import kotlinx.datetime.Instant
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import xyz.wingio.fediapi.URL

/**
* Represents a proof from an external identity provider.
*
* @param provider The name of the identity provider.
* @param providerUsername The account owner’s username on the identity provider’s service.
* @param updatedAt When the identity proof was last updated.
* @param proofUrl A link to a statement of identity proof, hosted by the identity provider.
* @param profileUrl The account owner’s profile URL on the identity provider.
*/
@Deprecated("""
Identity proofs have been deprecated in Mastodon v3.5.0 and newer.
Previously, the only proof provider was Keybase, but development
on Keybase has stalled entirely since it was acquired by Zoom.
""")
@Serializable
public data class IdentityProof(
val provider: String,
@SerialName("provider_username") val providerUsername: String,
@SerialName("updated_at") val updatedAt: Instant,
@SerialName("proof_url") val proofUrl: URL,
@SerialName("profile_url") val profileUrl: URL
)
Loading
Loading