-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #107 from takke/add_labeler_getServices
Add `labeler.getServices`
- Loading branch information
Showing
16 changed files
with
289 additions
and
0 deletions.
There are no files selected for viewing
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
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
19 changes: 19 additions & 0 deletions
19
core/src/commonMain/kotlin/work/socialhub/kbsky/api/app/bsky/LabelerResource.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,19 @@ | ||
package work.socialhub.kbsky.api.app.bsky | ||
|
||
import work.socialhub.kbsky.api.entity.app.bsky.labeler.LabelerGetServicesRequest | ||
import work.socialhub.kbsky.api.entity.app.bsky.labeler.LabelerGetServicesResponse | ||
import work.socialhub.kbsky.api.entity.share.Response | ||
|
||
/** | ||
* Bluesky/Labeler | ||
* [Reference](https://github.com/bluesky-social/atproto/tree/main/lexicons/app/bsky/labeler) | ||
*/ | ||
interface LabelerResource { | ||
|
||
/** | ||
* Get information about a list of labeler services. | ||
*/ | ||
fun getServices( | ||
request: LabelerGetServicesRequest | ||
): Response<LabelerGetServicesResponse> | ||
} |
12 changes: 12 additions & 0 deletions
12
...Main/kotlin/work/socialhub/kbsky/api/entity/app/bsky/labeler/LabelerGetServicesRequest.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,12 @@ | ||
package work.socialhub.kbsky.api.entity.app.bsky.labeler | ||
|
||
import work.socialhub.kbsky.api.entity.share.AuthRequest | ||
import work.socialhub.kbsky.auth.AuthProvider | ||
|
||
class LabelerGetServicesRequest( | ||
auth: AuthProvider | ||
) : AuthRequest(auth) { | ||
|
||
lateinit var dids: List<String> | ||
var detailed: Boolean? = null | ||
} |
9 changes: 9 additions & 0 deletions
9
...ain/kotlin/work/socialhub/kbsky/api/entity/app/bsky/labeler/LabelerGetServicesResponse.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,9 @@ | ||
package work.socialhub.kbsky.api.entity.app.bsky.labeler | ||
|
||
import kotlinx.serialization.Serializable | ||
import work.socialhub.kbsky.model.app.bsky.labeler.LabelerViewUnion | ||
|
||
@Serializable | ||
class LabelerGetServicesResponse { | ||
lateinit var views: List<LabelerViewUnion> | ||
} |
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
43 changes: 43 additions & 0 deletions
43
core/src/commonMain/kotlin/work/socialhub/kbsky/internal/app/bsky/_LabelerResource.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,43 @@ | ||
package work.socialhub.kbsky.internal.app.bsky | ||
|
||
import kotlinx.coroutines.runBlocking | ||
import work.socialhub.kbsky.BlueskyConfig | ||
import work.socialhub.kbsky.BlueskyTypes.LabelerGetServices | ||
import work.socialhub.kbsky.api.app.bsky.LabelerResource | ||
import work.socialhub.kbsky.api.entity.app.bsky.labeler.LabelerGetServicesRequest | ||
import work.socialhub.kbsky.api.entity.app.bsky.labeler.LabelerGetServicesResponse | ||
import work.socialhub.kbsky.api.entity.share.Response | ||
import work.socialhub.kbsky.internal.share._InternalUtility.getWithAuth | ||
import work.socialhub.kbsky.internal.share._InternalUtility.proceed | ||
import work.socialhub.kbsky.internal.share._InternalUtility.xrpc | ||
import work.socialhub.kbsky.util.MediaType | ||
import work.socialhub.khttpclient.HttpRequest | ||
|
||
class _LabelerResource( | ||
private val config: BlueskyConfig | ||
) : LabelerResource { | ||
|
||
override fun getServices( | ||
request: LabelerGetServicesRequest | ||
): Response<LabelerGetServicesResponse> { | ||
|
||
return proceed { | ||
runBlocking { | ||
HttpRequest() | ||
.url(xrpc(config, LabelerGetServices)) | ||
.accept(MediaType.JSON) | ||
.also { req -> | ||
// dids=did1&dids=did2&... | ||
request.dids.forEach { | ||
req.query("dids", it) | ||
} | ||
request.detailed?.let { | ||
req.query("detailed", it) | ||
} | ||
} | ||
.getWithAuth(request.auth) | ||
} | ||
} | ||
} | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/labeler/LabelerPolicies.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,12 @@ | ||
package work.socialhub.kbsky.model.app.bsky.labeler | ||
|
||
import kotlinx.serialization.Serializable | ||
import work.socialhub.kbsky.model.com.atproto.label.LabelDefsLabelValueDefinition | ||
|
||
@Serializable | ||
class LabelerPolicies { | ||
|
||
lateinit var labelValues: List<String> | ||
|
||
var labelValueDefinitions: List<LabelDefsLabelValueDefinition> = emptyList() | ||
} |
26 changes: 26 additions & 0 deletions
26
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/labeler/LabelerView.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,26 @@ | ||
package work.socialhub.kbsky.model.app.bsky.labeler | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import work.socialhub.kbsky.BlueskyTypes | ||
import work.socialhub.kbsky.model.app.bsky.actor.ActorDefsProfileView | ||
import work.socialhub.kbsky.model.com.atproto.label.LabelDefsLabel | ||
|
||
@Serializable | ||
class LabelerView : LabelerViewUnion() { | ||
|
||
companion object { | ||
val TYPE = BlueskyTypes.LabelerDefs + "#labelerView" | ||
} | ||
|
||
@SerialName("\$type") | ||
override var type = TYPE | ||
|
||
lateinit var uri: String | ||
lateinit var cid: String | ||
lateinit var creator: ActorDefsProfileView | ||
var likeCount: Int? = null | ||
var viewer: LabelerViewerState? = null | ||
var indexedAt: String? = null | ||
var labels: List<LabelDefsLabel>? = null | ||
} |
27 changes: 27 additions & 0 deletions
27
.../src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/labeler/LabelerViewDetailed.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,27 @@ | ||
package work.socialhub.kbsky.model.app.bsky.labeler | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import work.socialhub.kbsky.BlueskyTypes | ||
import work.socialhub.kbsky.model.app.bsky.actor.ActorDefsProfileView | ||
import work.socialhub.kbsky.model.com.atproto.label.LabelDefsLabel | ||
|
||
@Serializable | ||
class LabelerViewDetailed : LabelerViewUnion() { | ||
|
||
companion object { | ||
val TYPE = BlueskyTypes.LabelerDefs + "#labelerViewDetailed" | ||
} | ||
|
||
@SerialName("\$type") | ||
override var type = TYPE | ||
|
||
lateinit var uri: String | ||
lateinit var cid: String | ||
lateinit var creator: ActorDefsProfileView | ||
lateinit var policies: LabelerPolicies | ||
var likeCount: Int? = null | ||
var viewer: LabelerViewerState? = null | ||
var indexedAt: String? = null | ||
var labels: List<LabelDefsLabel>? = null | ||
} |
18 changes: 18 additions & 0 deletions
18
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/labeler/LabelerViewUnion.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,18 @@ | ||
package work.socialhub.kbsky.model.app.bsky.labeler | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
import work.socialhub.kbsky.util.json.LabelerViewPolymorphicSerializer | ||
|
||
/** | ||
* @see LabelerView | ||
* @see LabelerViewDetailed | ||
*/ | ||
@Serializable(with = LabelerViewPolymorphicSerializer::class) | ||
abstract class LabelerViewUnion { | ||
@SerialName("\$type") | ||
abstract var type: String | ||
|
||
val asLabelerView get() = this as? LabelerView | ||
val asLabelerViewDetailed get() = this as? LabelerViewDetailed | ||
} |
9 changes: 9 additions & 0 deletions
9
core/src/commonMain/kotlin/work/socialhub/kbsky/model/app/bsky/labeler/LabelerViewerState.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,9 @@ | ||
package work.socialhub.kbsky.model.app.bsky.labeler | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
class LabelerViewerState { | ||
|
||
var like: String? = null | ||
} |
23 changes: 23 additions & 0 deletions
23
...Main/kotlin/work/socialhub/kbsky/model/com/atproto/label/LabelDefsLabelValueDefinition.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,23 @@ | ||
package work.socialhub.kbsky.model.com.atproto.label | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
class LabelDefsLabelValueDefinition { | ||
|
||
// The value of the label being defined. Must only include lowercase ascii and the '-' character ([a-z-]+). | ||
lateinit var identifier: String | ||
|
||
// "inform", "alert", "none" | ||
lateinit var severity: String | ||
|
||
// "content", "media", "none" | ||
lateinit var blurs: String | ||
|
||
// "ignore", "warn", "hide" | ||
var defaultSetting: String = "" | ||
|
||
var adultOnly: Boolean = false | ||
|
||
lateinit var locales: List<LabelDefsLabelValueDefinitionStrings> | ||
} |
13 changes: 13 additions & 0 deletions
13
...tlin/work/socialhub/kbsky/model/com/atproto/label/LabelDefsLabelValueDefinitionStrings.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,13 @@ | ||
package work.socialhub.kbsky.model.com.atproto.label | ||
|
||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
class LabelDefsLabelValueDefinitionStrings { | ||
|
||
lateinit var lang: String | ||
|
||
lateinit var name: String | ||
|
||
lateinit var description: String | ||
} |
34 changes: 34 additions & 0 deletions
34
.../src/commonMain/kotlin/work/socialhub/kbsky/util/json/LabelerViewPolymorphicSerializer.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,34 @@ | ||
package work.socialhub.kbsky.util.json | ||
|
||
import kotlinx.serialization.DeserializationStrategy | ||
import kotlinx.serialization.Serializable | ||
import kotlinx.serialization.json.JsonContentPolymorphicSerializer | ||
import kotlinx.serialization.json.JsonElement | ||
import work.socialhub.kbsky.model.app.bsky.labeler.LabelerView | ||
import work.socialhub.kbsky.model.app.bsky.labeler.LabelerViewDetailed | ||
import work.socialhub.kbsky.model.app.bsky.labeler.LabelerViewUnion | ||
import work.socialhub.kbsky.util.json.JsonElementUtil.type | ||
|
||
object LabelerViewPolymorphicSerializer : | ||
JsonContentPolymorphicSerializer<LabelerViewUnion>( | ||
LabelerViewUnion::class | ||
) { | ||
|
||
override fun selectDeserializer( | ||
element: JsonElement | ||
): DeserializationStrategy<LabelerViewUnion> { | ||
return when (val type = element.type()) { | ||
LabelerView.TYPE -> LabelerView.serializer() | ||
LabelerViewDetailed.TYPE -> LabelerViewDetailed.serializer() | ||
else -> { | ||
println("[Warning] Unknown Item type: $type (LabelerViewUnion)") | ||
Unknown.serializer() | ||
} | ||
} | ||
} | ||
|
||
@Serializable | ||
class Unknown : LabelerViewUnion() { | ||
override var type: String = "unknown" | ||
} | ||
} |
30 changes: 30 additions & 0 deletions
30
core/src/jvmTest/kotlin/work/socialhub/kbsky/app/bsky/labeler/GetServicesTest.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,30 @@ | ||
package work.socialhub.kbsky.app.bsky.labeler | ||
|
||
import work.socialhub.kbsky.AbstractTest | ||
import work.socialhub.kbsky.BlueskyFactory | ||
import work.socialhub.kbsky.api.entity.app.bsky.labeler.LabelerGetServicesRequest | ||
import work.socialhub.kbsky.domain.Service.BSKY_SOCIAL | ||
import kotlin.test.Test | ||
|
||
class GetServicesTest : AbstractTest() { | ||
|
||
@Test | ||
fun testGetServices() { | ||
val response = BlueskyFactory | ||
.instance(BSKY_SOCIAL.uri) | ||
.labeler() | ||
.getServices( | ||
LabelerGetServicesRequest(auth()).also { | ||
it.dids = listOf("did:plc:ar7c4by46qjdydhdevvrndac", "did:plc:fcikraffwejtuqffifeykcml") | ||
it.detailed = true | ||
} | ||
) | ||
|
||
response.data.views | ||
.forEach { | ||
println(it.asLabelerViewDetailed?.creator?.displayName) | ||
println(" likes: " + it.asLabelerViewDetailed?.likeCount) | ||
println(" labelValues: " + it.asLabelerViewDetailed?.policies?.labelValues) | ||
} | ||
} | ||
} |