This library is a ATProtocol and Bluesly API client on kotlin.
ATProtocol core library.
ATProtocol extention for Bluesky.
if you want to access Bluesky resources, you also need this module.
repositories {
mavenCentral()
}
implementation("io.github.milkcocoa0902:milkyway-core:0.0.3")
// Bluesky extension
implementation("io.github.milkcocoa0902:milkyway-bsky:0.0.3")
if you use milkyway-bsky
, one of action which shown below is needed.
telling the bsky serializersModules to bsky-core
's serializer.
Milkyway.installBskyDependencies()
when call bsky extension, same as above code will run inside constructor.
Milkyway.bsky()
when you call getRecord which record of bluesky before telling the dependency to Milkyway, it fails because milkyway dont know subclass of Record
which implemented in milkyway-bsky
.
so you have to tell the hint.
in below case, FeedPostRecord
registered as Record
subclass.
as a result, when API returns it, you can get it.(but if not, you cannot get. only affect as a hint)
client.atProtocol()
.repo()
.getRecord<FeedPostRecord>(
request = GetRecord.GetRecordRequest(
collection = uri.collection!!,
repo = uri.did?.value!!,
rkey = uri.rkey!!
)
)
after it, you dont need to call with type. because FeedPostRecord
was registered.
client.atProtocol()
.repo()
.getRecord(
request = GetRecord.GetRecordRequest(
collection = uri.collection!!,
repo = uri.did?.value!!,
rkey = uri.rkey!!
)
)
Milkyway provides all of api via client.
so first, you need to get client.
val client = Milkyway.instance(domain = OfficialDomain.Bsky)
now you can use api.
and then, create a session for getting a credentials which needed to authorize requests.
val session =
client.atProtocol()
.server()
.createSession(
CreateSession.CreateSessionRequest(
identifier = System.getenv("BSKY_IDENTIFIER"), // replace your own identifier. example - bsky.milkcocoa.info
password = System.getenv("BSKY_PASSWORD") // replace your own password
)
)
println(session.accessJwt)
//
client.atProtocol()
.server()
.refreshSession(
request =
RefreshSession.RefreshSessionRequest(
refreshJwt = refreshJwt
)
)
client.atProtocol()
.repo()
.createRecord(request = CreateRecord.CreateRecordRequest(
accessJwt = session.accessJwt,
repo = session.handle.value,
collection = NSID("app.bsky.feed.post"),
record = FeedPostRecord(
text = "post from milkyway!!!!",
createdAt = LocalDateTime.now(),
)
))
client.bsky()
.actor()
.getProfile(request = GetProfile.GetProfileRequest(
accessJwt = session.accessJwt,
actor = session.did
))
val timeline =
client.bsky()
.feed()
.getTimeline(
GetTimeLine.GetTimelineRequest(
accessJwt = session.accessJwt,
cursor = "",
limit = 10
)
)
for (f in timeline.feed) {
when (f.post.record) {
is FeedPostRecord -> println((f.post.record as FeedPostRecord).text)
else -> println(f.post.record.type)
}
}
}