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

code-check/github-api-scala: GitHubAPI wrapper for scala

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

开源软件名称:

code-check/github-api-scala

开源软件地址:

https://github.com/code-check/github-api-scala

开源编程语言:

Scala 100.0%

开源软件介绍:

GitHubAPI for scala

Build Status Latest version

GitHubAPI wrapper for scala

Dependencies

  • joda-time
  • json4s
  • async-http-client

Getting started

To develop this, you have to get GitHub API Token.
You can get it from here.

Add this library and an HTTP client library to your build.sbt file. Both versions 1.9 and 2.0 of the Asnyc HTTP Client are supported, so you choose. Ning's HTTP client will request a log binding, so we'll provide a basic one.

libraryDependencies ++= Seq(
  "com.ning" % "async-http-client" % "1.9.40",
  "org.slf4j" % "slf4j-simple" % "1.7.26",
  "io.code-check" %% "github-api" % "0.3.0"
)

Using the code is as simple as starting an HTTP client instance, and providing it to the main API class.

import com.ning.http.client.AsyncHttpClient

import codecheck.github.transport.asynchttp19.AsyncHttp19Transport
import codecheck.github.api.GitHubAPI
import codecheck.github.models._

import org.slf4j.LoggerFactory

import scala.concurrent.Await
import scala.concurrent.duration._
import scala.concurrent.ExecutionContext.Implicits.global
import scala.concurrent.Future

object Main {

  val logger = LoggerFactory.getLogger(getClass)

  def main(args: Array[String]): Unit = {

    val githubToken = "a0b1c2d3e4f5g6h7ijklmnopqrst5u4v3w2x1y0z"

    val httpClient = new AsyncHttp19Transport(new AsyncHttpClient())
    
    val githubApi = new GitHubAPI(githubToken, httpClient)
    
    val repoParams =
      RepositoryListOption(
        RepositoryListType.public,
        RepositorySort.updated,
        SortDirection.desc
      )
    
    val repoListOp: Future[List[Repository]] =
      githubApi.listOwnRepositories(repoParams)

    val exec: Future[Unit] =
      for (repos <- repoListOp) 
      yield
        for (repo <- repos)
        yield println(repoToJson(repo))

    exec.onFailure {
      case e: Throwable => logger.error(e.toString)
    }

    Await.ready(exec, Duration.Inf)

    httpClient.close
  }

  /** Unsophisticated JSON serialization */
  def repoToJson(repo: Repository): String =
    s"""{
       |  id: ${repo.id},
       |  name: "${repo.name}",
       |  full_name: "${repo.full_name}",
       |  url: "${repo.url}",
       |  description: "${repo.description.getOrElse("")}",
       |  owner: "${repo.owner.login}",
       |  open_issues_count: ${repo.open_issues_count}
       |}""".stripMargin

}

How to develop

export GITHUB_USER=[Your GitHub username] 
export GITHUB_REPO=[Your GitHub test repo] 
export GITHUB_TOKEN=[Your GitHub Token] 
git clone -o upstream [email protected]:code-check/github-api.git
cd github-api
sbt test

Currently, Java 8 is required to build this library. If you have multiple versions of Java installed on your system, set it to Java 8 (also known as version 1.8). One method for choosing the Java version is to override the value of JAVA_HOME in the environment sbt runs.

$ env JAVA_HOME="$(/usr/libexec/java_home -v 1.8)" sbt

About models

We don't aim to define all fields of JSON. Because these are too much and might be changed by GitHub.

We just define the fields we need.

License

MIT




鲜花

握手

雷人

路过

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

请发表评论

全部评论

专题导读
上一篇:
ytester2/github-api: github-api发布时间:2022-06-11
下一篇:
JasonSanford/gitspatial: A spatial API for your GitHub-hosted GeoJSON发布时间:2022-06-11
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

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

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

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