在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
开源软件名称:code-check/github-api-scala开源软件地址:https://github.com/code-check/github-api-scala开源编程语言:Scala 100.0%开源软件介绍:GitHubAPI for scalaGitHubAPI wrapper for scala Dependencies
Getting startedTo develop this, you have to get GitHub API Token. Add this library and an HTTP client library to your 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 developexport 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
About modelsWe 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. LicenseMIT |
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论