User API

Github4s supports the User API. As a result, with Github4s, you can interacts with:


import cats.effect.IO
import github4s.Github
import org.http4s.client.{Client, JavaNetClientBuilder}


val httpClient: Client[IO] = JavaNetClientBuilder[IO].create // You can use any http4s backend

val accessToken = sys.env.get("GITHUB_TOKEN")
val gh = Github[IO](httpClient, accessToken)

Users

Get a user

Get information for a particular user.

You can get a user using get, it takes as argument:

  • username: of the user to retrieve.
val getUser = gh.users.get("rafaparadela")
getUser.flatMap(_.result match {
  case Left(e)  => IO.println(s"Something went wrong: ${e.getMessage}")
  case Right(r) => IO.println(r)
})

The result on the right is the corresponding User.

See the API doc for full reference.

Get an authenticated user

Get information of the authenticated user making the API call.

You can get an authenticated user using getAuth:

val getAuth = gh.users.getAuth()
getAuth.flatMap(_.result match {
  case Left(e)  => IO.println(s"Something went wrong: ${e.getMessage}")
  case Right(r) => IO.println(r)
})

The result on the right is the corresponding User.

See the API doc for full reference.

Get a list of users

You can get a list of users using getUsers, it takes as arguments:

  • since: The integer ID of the last User that you’ve seen.
  • pagination: Limit and Offset for pagination.
val getUsers = gh.users.getUsers(1)
getUsers.flatMap(_.result match {
  case Left(e)  => IO.println(s"Something went wrong: ${e.getMessage}")
  case Right(r) => IO.println(r)
})

The result on the right is the corresponding List[User].

See the API doc for full reference.

As you can see, a few features of the user endpoint are missing.

As a result, if you’d like to see a feature supported, feel free to create an issue and/or a pull request!

List users followed by another user

You can get a list of users followed by another user using getFollowing, it takes as argument:

  • username: of the user to retrieve.
  • pagination: Limit and Offset for pagination, optional.
val getFollowing = gh.users.getFollowing("rafaparadela")
getFollowing.flatMap(_.result match {
  case Left(e)  => IO.println(s"Something went wrong: ${e.getMessage}")
  case Right(r) => IO.println(r)
})

The result on the right is the corresponding List[User].

See the API doc for full reference.

List email addresses for the authenticated user

You can get a list of emails associated with the authenticated user using getEmails, it takes as argument:

  • pagination: Limit and Offset for pagination, optional.
val getEmails = gh.users.getEmails()
getEmails.flatMap(_.result match {
  case Left(e)  => IO.println(s"Something went wrong: ${e.getMessage}")
  case Right(r) => IO.println(r)
})

The result on the right is the corresponding List[Email].

See the API doc for full reference.