-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
* #299 Implement oEmbed API methods * Set "rich" as default meta data type and remove kDoc * Unify kDoc for easy-access method vals on MastodonClient * Sort endpoints alphabetically
- Loading branch information
1 parent
8b6642a
commit 1e8bf81
Showing
8 changed files
with
311 additions
and
42 deletions.
There are no files selected for viewing
35 changes: 35 additions & 0 deletions
35
bigbone-rx/src/main/kotlin/social/bigbone/rx/RxOEmbedMethods.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package social.bigbone.rx | ||
|
||
import io.reactivex.rxjava3.core.Single | ||
import social.bigbone.MastodonClient | ||
import social.bigbone.api.entity.OEmbedMetadata | ||
import social.bigbone.api.method.OEmbedMethods | ||
|
||
/** | ||
* Reactive implementation of [OEmbedMethods]. For generating OEmbed previews. | ||
* @see <a href="https://docs.joinmastodon.org/methods/oembed/">Mastodon oembed API methods</a> | ||
*/ | ||
class RxOEmbedMethods(private val mastodonClient: MastodonClient) { | ||
|
||
private val oEmbedMethods = OEmbedMethods(mastodonClient) | ||
|
||
/** | ||
* Get oEmbed info as JSON. | ||
* @see <a href="https://docs.joinmastodon.org/methods/oembed/#get">Mastodon API documentation: methods/oembed/#get</a> | ||
* @param urlOfStatus URL of a status for which to return oEmbed info. | ||
* @param maxWidth Width of the iframe. Defaults to 400. | ||
* @param maxHeight Height of the iframe. Defaults to null. | ||
*/ | ||
@JvmOverloads | ||
fun getOEmbedInfoAsJson( | ||
urlOfStatus: String, | ||
maxWidth: Int = 400, | ||
maxHeight: Int? = null | ||
): Single<OEmbedMetadata> = Single.fromCallable { | ||
oEmbedMethods.getOEmbedInfoAsJson( | ||
urlOfStatus = urlOfStatus, | ||
maxWidth = maxWidth, | ||
maxHeight = maxHeight | ||
).execute() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
83 changes: 83 additions & 0 deletions
83
bigbone/src/main/kotlin/social/bigbone/api/entity/OEmbedMetadata.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package social.bigbone.api.entity | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import social.bigbone.api.method.OEmbedMethods | ||
|
||
/** | ||
* oEmbed metadata returned by [OEmbedMethods]. | ||
* @see <a href="https://oembed.com/#section2.3">OEmbed response parameters documentation</a> | ||
*/ | ||
@Serializable | ||
data class OEmbedMetadata( | ||
/** | ||
* The resource type. | ||
* For now, this will always be "rich". | ||
*/ | ||
@SerialName("type") | ||
val type: String = "rich", | ||
|
||
/** | ||
* The oEmbed version number. Must be 1.0. | ||
*/ | ||
@SerialName("version") | ||
val version: String = "1.0", | ||
|
||
/** | ||
* A text title, describing this resource. | ||
*/ | ||
@SerialName("title") | ||
val title: String? = "", | ||
|
||
/** | ||
* The name of the author/owner of the resource. | ||
*/ | ||
@SerialName("author_name") | ||
val authorName: String? = "", | ||
|
||
/** | ||
* A URL for the other/owner of the resource. | ||
*/ | ||
@SerialName("author_url") | ||
val authorUrl: String? = "", | ||
|
||
/** | ||
* The name of the resource provider. | ||
*/ | ||
@SerialName("provider_name") | ||
val providerName: String? = "", | ||
|
||
/** | ||
* The URL of the resource provider. | ||
*/ | ||
@SerialName("provider_url") | ||
val providerUrl: String? = "", | ||
|
||
/** | ||
* The suggested cache lifetime for this resource, in seconds. | ||
* Consumers may choose to use this value or not. | ||
*/ | ||
@SerialName("cache_age") | ||
val cacheAge: Int? = null, | ||
|
||
/** | ||
* The HTML required to display the resource. | ||
* The HTML should have no padding or margins. | ||
* Consumers may wish to load the HTML in an off-domain iframe to avoid XSS vulnerabilities. | ||
* The markup should be valid XHTML 1.0 Basic. | ||
*/ | ||
@SerialName("html") | ||
val html: String? = "", | ||
|
||
/** | ||
* The width in pixels required to display the HTML. | ||
*/ | ||
@SerialName("width") | ||
val width: Int? = null, | ||
|
||
/** | ||
* The height in pixels required to display the HTML. | ||
*/ | ||
@SerialName("height") | ||
val height: Int? = null | ||
) |
Oops, something went wrong.