defmodule Gullintanni.Providers.GitHub do
  @behaviour Gullintanni.Provider

  def validate_config(config) do
    unless config[:provider_auth_token] do
      raise ArgumentError, "missing :provider_auth_token configuration"
    end

    :ok
  end

  def whoami(config) do
    Tentacat.Users.me(client(config))["login"]
  end

  defp client(config) do
    Tentacat.Client.new(%{access_token: config[:provider_auth_token]})
  end
end

defmodule Gullintanni.Providers.GitHub do
  @behaviour Gullintanni.Provider

  @default_endpoint "https://api.github.com/"

  def validate_config(config) do
    unless config[:provider_auth_token] do
      raise ArgumentError, "missing :provider_auth_token configuration"
    end

    :ok
  end

  def whoami(config) do
    Tentacat.Users.me(client(config))["login"]
  end

  defp client(config) do
    endpoint = config[:provider_endpoint] || @default_endpoint
    Tentacat.Client.new(%{access_token: config[:provider_auth_token]}, endpoint)
  end
end

Allow configuration of the GitHub API endpoint URL
Allow configuration of the GitHub API endpoint URL

Defaults to the regular (non-enterprise) API endpoint.

gullintanni/gullintanni,gullintanni/gullintanni