• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

schwitzerm/scaladon: Mastodon social network API implementation in Scala

原作者: [db:作者] 来自: 网络 收藏 邀请

开源软件名称(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

Build Status

scaladon

A 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 work

Uploading 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 project

Simply add the following to your build.sbt file:

libraryDependencies += "ca.schwitzer" %% "scaladon" % "0.3.2"

Examples

Tooting 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 Manager

I'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!




鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
dysk0/harbour-tooter: Mastodon is a free, open-source social network. A decentra ...发布时间:2022-08-17
下一篇:
mastodon-sc/mastodon-tomancak发布时间:2022-08-17
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap