在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称(OpenSource Name):schwitzerm/scaladon开源软件地址(OpenSource Url):https://github.com/schwitzerm/scaladon开源编程语言(OpenSource Language):Scala 100.0%开源软件介绍(OpenSource Introduction):NOTE:This project is no longer maintained. See the below fork for an updated library. https://github.com/Sciss/scaladon scaladonA Mastodon social network API implementation in Scala using Akka HTTP and Akka Streams. This project is in its infancy, but is ready for more testing. Currently supports Scala versions 2.11 and 2.12. What doesn't workUploading media, changing user settings (display name/e-mail/avatar/header), and posting toots with attachments. I seek to resolve this swiftly. (I did not resolve this swiftly.) Including in a projectSimply add the following to your build.sbt file:
ExamplesTooting a status (using map/flatMap): package ca.schwitzer.scaladon
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import ca.schwitzer.scaladon.Mastodon
import ca.schwitzer.scaladon.models._
import scala.concurrent.ExecutionContext.Implicits.global //we need an ExecutionContext
import scala.concurrent.Future
object MyMastodonApp extends App {
implicit val system = ActorSystem() //an ActorSystem
implicit val materializer = ActorMaterializer() //and an ActorMaterializer
val appFuture = Mastodon.createApp("marxism.party", "mycoolapp")
val tokenFuture = appFuture.flatMap(_.login("[email protected]", "thisshouldreallybsupersecure"))
val statusFuture: Future[Status] = appFuture.flatMap { app =>
tokenFuture.flatMap { token =>
app.toot("I'm tooting from the Scaladon API!", StatusVisibilities.Public)(token).map {
case MastodonResponses.Success(elem) => elem
case e: MastodonError => throw e.asThrowable
}
}
}
} Fetching an account (using for comprehension): package ca.schwitzer.scaladon
import akka.actor.ActorSystem
import akka.stream.ActorMaterializer
import ca.schwitzer.scaladon.Mastodon
import ca.schwitzer.scaladon.models._
import scala.concurrent.ExecutionContext.Implicits.global //we need an ExecutionContext
import scala.concurrent.Future
object MyMastodonApp extends App {
implicit val system = ActorSystem() //an ActorSystem
implicit val materializer = ActorMaterializer() //and an ActorMaterializer
val appFuture = Mastodon.createApp("marxism.party", "mycoolapp")
val tokenFuture = appFuture.flatMap(_.login("[email protected]", "thisshouldreallybsupersecure"))
val accountFuture: Future[Account] = for {
app <- appFuture
token <- tokenFuture
account <- app.Accounts.fetch(1)(token)
} yield account match {
case MastodonResponses.Success(elem) => elem
case e: MastodonError => throw e.asThrowable
}
} Etc...More examples and full code documentation will be coming soon. For now, just take a look at the source code. About Project ManagerI'm Mitchell Schwitzer and I enjoy to work on all sorts of things, especially in Scala. If you have any questions or recommendations, please get to me at [email protected], or at [email protected] on the Fediverse! |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论