GitHub

Build StatusCoverage StatusLatest Version

The simplest Elixir client for GitHub REST API v3.

Contents

Usage

With OAuth access token

Github library supports multiple API Resources. For example, Github.Users.Emails.list! allows getting user's emails:

iex> github_client = %Github.Client{access_token: "access_token"}

iex> github_client |> Github.Users.Emails.list!()
%Github.Client.Response{
  status: 200,
  headers: [{"Server", "GitHub.com"}, ...],
  body: [%{"email" => "hello@workflowci.com", "primary" => true, "verified" => true, "visibility" => "public"}, ...],
  ...
}

With App JWT token

To authenticate with a GitHub App and make an API call by using a JWT token:

iex> jwt_token = Github.Client.generate_jwt_token(app_id: 12345, private_key_filepath: "app.pem")

iex> github_client = %Github.Client{jwt_token: "jwt_token"}

iex> github_client |> Github.Apps.Installations.find!(67890)
%Github.Client.Response{
  status: 200,
  headers: [...],
  body: %{"id" => 12345, ...},
  ...
}

Pagination

For pagination, the client has such functions as Github.Client.fetch_more! and Github.Client.fetch_all!. Here is an example:

iex> github_client = %Github.Client{access_token: "access_token"}

iex> first_page = github_client |> Github.Users.Emails.list!(page: 1, per_page: 1)
%Github.Client.Response{
  status: 200,
  headers: [...],
  body: [...],
  next_page: 2,
  last_page: 3,
  next_url: "https://api.github.com/user/emails?page=2&per_page=1",
  last_url: "https://api.github.com/user/emails?page=3&per_page=1",
  ...
}

iex> Github.Client.fetch_more!(first_page)
%Github.Client.Response{
  status: 200,
  headers: [...],
  body: [...],
  next_page: 3,
  last_page: 3,
  next_url: "https://api.github.com/user/emails?page=3&per_page=1",
  last_url: "https://api.github.com/user/emails?page=3&per_page=1",
  ...
}

Please visit hexdocs.pm/github to find more code examples.

API Resources

Installation

The package can be installed by adding github to your list of dependencies in mix.exs:

def deps do
  [
    {:github, "~> 0.10.0"}
  ]
end

Testing

mix deps.get
mix test