defmodule HardHat.Users do
  @moduledoc """
  A wrapper for the Users entity.

  <https://docs.travis-ci.com/api/#users>
  """

  import HardHat
  alias HardHat.Client

  @doc """
  Show the authenticated user.

  ## Examples

      HardHat.Users.whoami(client)
  """
  @spec whoami(Client.t) :: HardHat.response
  def whoami(client) do
    get(client, "users")
  end

  @doc """
  Show the user identified by `id`.

  ## Examples

      HardHat.Users.show(client, 267)
  """
  @spec show(Client.t, pos_integer) :: HardHat.response
  def show(client, id) do
    get(client, "users/#{id}")
  end

  @doc """
  Trigger a new sync with GitHub.

  ## Examples

      HardHat.Users.sync(client)
  """
  @spec sync(Client.t) :: HardHat.response
  def sync(client) do
    post(client, "users/sync")
  end
end

defmodule HardHat.Users do
  @moduledoc """
  A wrapper for the Users entity.

  <https://docs.travis-ci.com/api/#users>
  """

  import HardHat, except: [get: 2]
  alias HardHat.Client

  @doc """
  Show the authenticated user.

  ## Examples

      HardHat.Users.whoami(client)
  """
  @spec whoami(Client.t) :: HardHat.response
  def whoami(client) do
    HardHat.get(client, "users")
  end

  @doc """
  Gets the user identified by `id`.

  ## Examples

      HardHat.Users.get(client, 267)
      HardHat.Users.get(client, "267")
  """
  @spec get(Client.t, pos_integer | String.t) :: HardHat.response
  def get(client, id) when is_integer(id) and id > 0 do
    HardHat.get(client, "users/#{id}")
  end
  def get(client, id) when is_binary(id) do
    get(client, String.to_integer(id))
  end

  @doc """
  Trigger a new sync with GitHub.

  ## Examples

      HardHat.Users.sync(client)
  """
  @spec sync(Client.t) :: HardHat.response
  def sync(client) do
    post(client, "users/sync")
  end
end

Use the verb "get" for consistency
Use the verb "get" for consistency

Rather that use the inconsistent verbs that are in place in the upstream
API documentation, I think it makes sense to standardize on using "get"
for pure GET requests, which also is familiar to other usages of the
term throughout Elixir as a language. The verbs "fetch" and "show"
either have different meanings in Elixir, or are not used, so I think
this will make the wrapper feel more native.

gullintanni/gullintanni,gullintanni/gullintanni