Skip to main content

lib/api/users/users.ex

# Generated by `mix github.gen` from docs/github-api/api.github.com.json.
# Do not edit by hand; re-run the task instead.

defmodule Noizu.Github.Api.Users do
  @moduledoc """
  GitHub `users` API.
  """
  import Noizu.Github

  @doc """
  Add an email address for the authenticated user

  @see https://docs.github.com/rest/users/emails#add-an-email-address-for-the-authenticated-user
  """
  def add_email_for_authenticated_user(body, options \\ nil) do
    url = github_base() <> "/user/emails"
    body = body
    api_call(:post, url, body, Noizu.Github.Collection.Email, options)
  end

  @doc """
  Add social accounts for the authenticated user

  @see https://docs.github.com/rest/users/social-accounts#add-social-accounts-for-the-authenticated-user
  """
  def add_social_account_for_authenticated_user(body, options \\ nil) do
    url = github_base() <> "/user/social_accounts"
    body = body
    api_call(:post, url, body, Noizu.Github.Collection.SocialAccount, options)
  end

  @doc """
  Block a user

  @see https://docs.github.com/rest/users/blocking#block-a-user
  """
  def block(username, body, options \\ nil) do
    url = github_base() <> "/user/blocks/#{username}"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Check if a user is blocked by the authenticated user

  @see https://docs.github.com/rest/users/blocking#check-if-a-user-is-blocked-by-the-authenticated-user
  """
  def check_blocked(username, options \\ nil) do
    url = github_base() <> "/user/blocks/#{username}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Check if a user follows another user

  @see https://docs.github.com/rest/users/followers#check-if-a-user-follows-another-user
  """
  def check_following_for_user(username, target_user, options \\ nil) do
    url = github_base() <> "/users/#{username}/following/#{target_user}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Check if a person is followed by the authenticated user

  @see https://docs.github.com/rest/users/followers#check-if-a-person-is-followed-by-the-authenticated-user
  """
  def check_person_is_followed_by_authenticated(username, options \\ nil) do
    url = github_base() <> "/user/following/#{username}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Create a GPG key for the authenticated user

  @see https://docs.github.com/rest/users/gpg-keys#create-a-gpg-key-for-the-authenticated-user
  """
  def create_gpg_key_for_authenticated_user(body, options \\ nil) do
    url = github_base() <> "/user/gpg_keys"
    body = body
    api_call(:post, url, body, Noizu.Github.GpgKey, options)
  end

  @doc """
  Create a public SSH key for the authenticated user

  @see https://docs.github.com/rest/users/keys#create-a-public-ssh-key-for-the-authenticated-user
  """
  def create_public_ssh_key_for_authenticated_user(body, options \\ nil) do
    url = github_base() <> "/user/keys"
    body = body
    api_call(:post, url, body, Noizu.Github.Key, options)
  end

  @doc """
  Create a SSH signing key for the authenticated user

  @see https://docs.github.com/rest/users/ssh-signing-keys#create-a-ssh-signing-key-for-the-authenticated-user
  """
  def create_ssh_signing_key_for_authenticated_user(body, options \\ nil) do
    url = github_base() <> "/user/ssh_signing_keys"
    body = body
    api_call(:post, url, body, Noizu.Github.SshSigningKey, options)
  end

  @doc """
  Delete attestations in bulk

  @see https://docs.github.com/rest/users/attestations#delete-attestations-in-bulk
  """
  def delete_attestations_bulk(username, body, options \\ nil) do
    url = github_base() <> "/users/#{username}/attestations/delete-request"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete attestations by ID

  @see https://docs.github.com/rest/users/attestations#delete-attestations-by-id
  """
  def delete_attestations_by_id(username, attestation_id, options \\ nil) do
    url = github_base() <> "/users/#{username}/attestations/#{attestation_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete attestations by subject digest

  @see https://docs.github.com/rest/users/attestations#delete-attestations-by-subject-digest
  """
  def delete_attestations_by_subject_digest(username, subject_digest, options \\ nil) do
    url = github_base() <> "/users/#{username}/attestations/digest/#{subject_digest}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete an email address for the authenticated user

  @see https://docs.github.com/rest/users/emails#delete-an-email-address-for-the-authenticated-user
  """
  def delete_email_for_authenticated_user(body, options \\ nil) do
    url = github_base() <> "/user/emails"
    body = body
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete a GPG key for the authenticated user

  @see https://docs.github.com/rest/users/gpg-keys#delete-a-gpg-key-for-the-authenticated-user
  """
  def delete_gpg_key_for_authenticated_user(gpg_key_id, options \\ nil) do
    url = github_base() <> "/user/gpg_keys/#{gpg_key_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete a public SSH key for the authenticated user

  @see https://docs.github.com/rest/users/keys#delete-a-public-ssh-key-for-the-authenticated-user
  """
  def delete_public_ssh_key_for_authenticated_user(key_id, options \\ nil) do
    url = github_base() <> "/user/keys/#{key_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete social accounts for the authenticated user

  @see https://docs.github.com/rest/users/social-accounts#delete-social-accounts-for-the-authenticated-user
  """
  def delete_social_account_for_authenticated_user(body, options \\ nil) do
    url = github_base() <> "/user/social_accounts"
    body = body
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete an SSH signing key for the authenticated user

  @see https://docs.github.com/rest/users/ssh-signing-keys#delete-an-ssh-signing-key-for-the-authenticated-user
  """
  def delete_ssh_signing_key_for_authenticated_user(ssh_signing_key_id, options \\ nil) do
    url = github_base() <> "/user/ssh_signing_keys/#{ssh_signing_key_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Follow a user

  @see https://docs.github.com/rest/users/followers#follow-a-user
  """
  def follow(username, body, options \\ nil) do
    url = github_base() <> "/user/following/#{username}"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get the authenticated user

  @see https://docs.github.com/rest/users/users#get-the-authenticated-user
  """
  def get_authenticated(options \\ nil) do
    url = github_base() <> "/user"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get a user using their ID

  @see https://docs.github.com/rest/users/users#get-a-user-using-their-id
  """
  def get_by_id(account_id, options \\ nil) do
    url = github_base() <> "/user/#{account_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get a user

  @see https://docs.github.com/rest/users/users#get-a-user
  """
  def get_by_username(username, options \\ nil) do
    url = github_base() <> "/users/#{username}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get contextual information for a user

  @see https://docs.github.com/rest/users/users#get-contextual-information-for-a-user
  """
  def get_context_for_user(username, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:subject_type, options, nil),
            get_field(:subject_id, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/users/#{username}/hovercard" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Hovercard, options)
  end

  @doc """
  Get a GPG key for the authenticated user

  @see https://docs.github.com/rest/users/gpg-keys#get-a-gpg-key-for-the-authenticated-user
  """
  def get_gpg_key_for_authenticated_user(gpg_key_id, options \\ nil) do
    url = github_base() <> "/user/gpg_keys/#{gpg_key_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.GpgKey, options)
  end

  @doc """
  Get a public SSH key for the authenticated user

  @see https://docs.github.com/rest/users/keys#get-a-public-ssh-key-for-the-authenticated-user
  """
  def get_public_ssh_key_for_authenticated_user(key_id, options \\ nil) do
    url = github_base() <> "/user/keys/#{key_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Key, options)
  end

  @doc """
  Get an SSH signing key for the authenticated user

  @see https://docs.github.com/rest/users/ssh-signing-keys#get-an-ssh-signing-key-for-the-authenticated-user
  """
  def get_ssh_signing_key_for_authenticated_user(ssh_signing_key_id, options \\ nil) do
    url = github_base() <> "/user/ssh_signing_keys/#{ssh_signing_key_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.SshSigningKey, options)
  end

  @doc """
  List users

  @see https://docs.github.com/rest/users/users#list-users
  """
  def list(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:since, options, nil),
            get_field(:per_page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/users" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.SimpleUser, options)
  end

  @doc """
  List attestations

  @see https://docs.github.com/rest/users/attestations#list-attestations
  """
  def list_attestations(username, subject_digest, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:before, options, nil),
            get_field(:after, options, nil),
            get_field(:predicate_type, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/users/#{username}/attestations/#{subject_digest}" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  List attestations by bulk subject digests

  @see https://docs.github.com/rest/users/attestations#list-attestations-by-bulk-subject-digests
  """
  def list_attestations_bulk(username, body, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:before, options, nil),
            get_field(:after, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/users/#{username}/attestations/bulk-list" <> qs
      )

    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  List users blocked by the authenticated user

  @see https://docs.github.com/rest/users/blocking#list-users-blocked-by-the-authenticated-user
  """
  def list_blocked_by_authenticated_user(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/user/blocks" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.SimpleUser, options)
  end

  @doc """
  List email addresses for the authenticated user

  @see https://docs.github.com/rest/users/emails#list-email-addresses-for-the-authenticated-user
  """
  def list_emails_for_authenticated_user(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/user/emails" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.Email, options)
  end

  @doc """
  List the people the authenticated user follows

  @see https://docs.github.com/rest/users/followers#list-the-people-the-authenticated-user-follows
  """
  def list_followed_by_authenticated_user(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/user/following" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.SimpleUser, options)
  end

  @doc """
  List followers of the authenticated user

  @see https://docs.github.com/rest/users/followers#list-followers-of-the-authenticated-user
  """
  def list_followers_for_authenticated_user(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/user/followers" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.SimpleUser, options)
  end

  @doc """
  List followers of a user

  @see https://docs.github.com/rest/users/followers#list-followers-of-a-user
  """
  def list_followers_for_user(username, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/users/#{username}/followers" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.SimpleUser, options)
  end

  @doc """
  List the people a user follows

  @see https://docs.github.com/rest/users/followers#list-the-people-a-user-follows
  """
  def list_following_for_user(username, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/users/#{username}/following" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.SimpleUser, options)
  end

  @doc """
  List GPG keys for the authenticated user

  @see https://docs.github.com/rest/users/gpg-keys#list-gpg-keys-for-the-authenticated-user
  """
  def list_gpg_keys_for_authenticated_user(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/user/gpg_keys" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.GpgKey, options)
  end

  @doc """
  List GPG keys for a user

  @see https://docs.github.com/rest/users/gpg-keys#list-gpg-keys-for-a-user
  """
  def list_gpg_keys_for_user(username, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/users/#{username}/gpg_keys" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.GpgKey, options)
  end

  @doc """
  List public email addresses for the authenticated user

  @see https://docs.github.com/rest/users/emails#list-public-email-addresses-for-the-authenticated-user
  """
  def list_public_emails_for_authenticated_user(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/user/public_emails" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.Email, options)
  end

  @doc """
  List public keys for a user

  @see https://docs.github.com/rest/users/keys#list-public-keys-for-a-user
  """
  def list_public_keys_for_user(username, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/users/#{username}/keys" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.KeySimple, options)
  end

  @doc """
  List public SSH keys for the authenticated user

  @see https://docs.github.com/rest/users/keys#list-public-ssh-keys-for-the-authenticated-user
  """
  def list_public_ssh_keys_for_authenticated_user(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/user/keys" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.Key, options)
  end

  @doc """
  List social accounts for the authenticated user

  @see https://docs.github.com/rest/users/social-accounts#list-social-accounts-for-the-authenticated-user
  """
  def list_social_accounts_for_authenticated_user(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/user/social_accounts" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.SocialAccount, options)
  end

  @doc """
  List social accounts for a user

  @see https://docs.github.com/rest/users/social-accounts#list-social-accounts-for-a-user
  """
  def list_social_accounts_for_user(username, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/users/#{username}/social_accounts" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.SocialAccount, options)
  end

  @doc """
  List SSH signing keys for the authenticated user

  @see https://docs.github.com/rest/users/ssh-signing-keys#list-ssh-signing-keys-for-the-authenticated-user
  """
  def list_ssh_signing_keys_for_authenticated_user(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/user/ssh_signing_keys" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.SshSigningKey, options)
  end

  @doc """
  List SSH signing keys for a user

  @see https://docs.github.com/rest/users/ssh-signing-keys#list-ssh-signing-keys-for-a-user
  """
  def list_ssh_signing_keys_for_user(username, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/users/#{username}/ssh_signing_keys" <> qs
      )

    body = %{}
    api_call(:get, url, body, Noizu.Github.Collection.SshSigningKey, options)
  end

  @doc """
  Set primary email visibility for the authenticated user

  @see https://docs.github.com/rest/users/emails#set-primary-email-visibility-for-the-authenticated-user
  """
  def set_primary_email_visibility_for_authenticated_user(body, options \\ nil) do
    url = github_base() <> "/user/email/visibility"
    body = body
    api_call(:patch, url, body, Noizu.Github.Collection.Email, options)
  end

  @doc """
  Unblock a user

  @see https://docs.github.com/rest/users/blocking#unblock-a-user
  """
  def unblock(username, options \\ nil) do
    url = github_base() <> "/user/blocks/#{username}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Unfollow a user

  @see https://docs.github.com/rest/users/followers#unfollow-a-user
  """
  def unfollow(username, options \\ nil) do
    url = github_base() <> "/user/following/#{username}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Update the authenticated user

  @see https://docs.github.com/rest/users/users#update-the-authenticated-user
  """
  def update_authenticated(body, options \\ nil) do
    url = github_base() <> "/user"
    body = body
    api_call(:patch, url, body, Noizu.Github.PrivateUser, options)
  end
end