github-api

The GitHub API from Scala with Async HTTP Client (Netty)

License

License

MIT
Categories

Categories

Github Development Tools Version Controls
GroupId

GroupId

io.code-check
ArtifactId

ArtifactId

github-api_2.10
Last Version

Last Version

0.2.0
Release Date

Release Date

Type

Type

jar
Description

Description

github-api
The GitHub API from Scala with Async HTTP Client (Netty)
Project URL

Project URL

http://github.com/code-check/github-api-scala
Project Organization

Project Organization

io.code-check
Source Code Management

Source Code Management

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

Download github-api_2.10

How to add to project

<!-- https://jarcasting.com/artifacts/io.code-check/github-api_2.10/ -->
<dependency>
    <groupId>io.code-check</groupId>
    <artifactId>github-api_2.10</artifactId>
    <version>0.2.0</version>
</dependency>
// https://jarcasting.com/artifacts/io.code-check/github-api_2.10/
implementation 'io.code-check:github-api_2.10:0.2.0'
// https://jarcasting.com/artifacts/io.code-check/github-api_2.10/
implementation ("io.code-check:github-api_2.10:0.2.0")
'io.code-check:github-api_2.10:jar:0.2.0'
<dependency org="io.code-check" name="github-api_2.10" rev="0.2.0">
  <artifact name="github-api_2.10" type="jar" />
</dependency>
@Grapes(
@Grab(group='io.code-check', module='github-api_2.10', version='0.2.0')
)
libraryDependencies += "io.code-check" % "github-api_2.10" % "0.2.0"
[io.code-check/github-api_2.10 "0.2.0"]

Dependencies

compile (5)

Group / Artifact Type Version
org.scala-lang : scala-library jar 2.10.6
org.json4s : json4s-jackson_2.10 jar 3.4.2
org.json4s : json4s-ext_2.10 jar 3.4.2
joda-time : joda-time jar 2.8.1
com.github.scopt : scopt_2.10 jar 3.5.0

provided (2)

Group / Artifact Type Version
com.ning : async-http-client jar 1.9.21
org.asynchttpclient : async-http-client jar 2.0.15

test (2)

Group / Artifact Type Version
org.slf4j : slf4j-nop jar 1.7.22
org.scalatest : scalatest_2.10 jar 3.0.1

Project Modules

There are no modules declared in this project.

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

io.code-check

codecheck

Versions

Version
0.2.0