Skip to main content

lib/api/apps/apps.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.Apps do
  @moduledoc """
  GitHub `apps` API.
  """
  import Noizu.Github

  @doc """
  Add a repository to an app installation

  @see https://docs.github.com/rest/apps/installations#add-a-repository-to-an-app-installation
  """
  def add_repo_to_installation_for_authenticated_user(
        installation_id,
        repository_id,
        body,
        options \\ nil
      ) do
    url = github_base() <> "/user/installations/#{installation_id}/repositories/#{repository_id}"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Check a token

  @see https://docs.github.com/rest/apps/oauth-applications#check-a-token
  """
  def check_token(client_id, body, options \\ nil) do
    url = github_base() <> "/applications/#{client_id}/token"
    body = body
    api_call(:post, url, body, Noizu.Github.Authorization, options)
  end

  @doc """
  Create a GitHub App from a manifest

  @see https://docs.github.com/rest/apps/apps#create-a-github-app-from-a-manifest
  """
  def create_from_manifest(code, body, options \\ nil) do
    url = github_base() <> "/app-manifests/#{code}/conversions"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Create an installation access token for an app

  @see https://docs.github.com/rest/apps/apps#create-an-installation-access-token-for-an-app
  """
  def create_installation_access_token(installation_id, body, options \\ nil) do
    url = github_base() <> "/app/installations/#{installation_id}/access_tokens"
    body = body
    api_call(:post, url, body, Noizu.Github.InstallationToken, options)
  end

  @doc """
  Delete an app authorization

  @see https://docs.github.com/rest/apps/oauth-applications#delete-an-app-authorization
  """
  def delete_authorization(client_id, body, options \\ nil) do
    url = github_base() <> "/applications/#{client_id}/grant"
    body = body
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete an installation for the authenticated app

  @see https://docs.github.com/rest/apps/apps#delete-an-installation-for-the-authenticated-app
  """
  def delete_installation(installation_id, options \\ nil) do
    url = github_base() <> "/app/installations/#{installation_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete an app token

  @see https://docs.github.com/rest/apps/oauth-applications#delete-an-app-token
  """
  def delete_token(client_id, body, options \\ nil) do
    url = github_base() <> "/applications/#{client_id}/token"
    body = body
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get the authenticated app

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

  @doc """
  Get an app

  @see https://docs.github.com/rest/apps/apps#get-an-app
  """
  def get_by_slug(app_slug, options \\ nil) do
    url = github_base() <> "/apps/#{app_slug}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Integration, options)
  end

  @doc """
  Get an installation for the authenticated app

  @see https://docs.github.com/rest/apps/apps#get-an-installation-for-the-authenticated-app
  """
  def get_installation(installation_id, options \\ nil) do
    url = github_base() <> "/app/installations/#{installation_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Installation, options)
  end

  @doc """
  Get an organization installation for the authenticated app

  @see https://docs.github.com/rest/apps/apps#get-an-organization-installation-for-the-authenticated-app
  """
  def get_org_installation(org, options \\ nil) do
    url = github_base() <> "/orgs/#{org}/installation"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Installation, options)
  end

  @doc """
  Get a repository installation for the authenticated app

  @see https://docs.github.com/rest/apps/apps#get-a-repository-installation-for-the-authenticated-app
  """
  def get_repo_installation(options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)
    url = github_base() <> "/repos/#{owner}/#{repo}/installation"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Installation, options)
  end

  @doc """
  Get a subscription plan for an account

  @see https://docs.github.com/rest/apps/marketplace#get-a-subscription-plan-for-an-account
  """
  def get_subscription_plan_for_account(account_id, options \\ nil) do
    url = github_base() <> "/marketplace_listing/accounts/#{account_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.MarketplacePurchase, options)
  end

  @doc """
  Get a subscription plan for an account (stubbed)

  @see https://docs.github.com/rest/apps/marketplace#get-a-subscription-plan-for-an-account-stubbed
  """
  def get_subscription_plan_for_account_stubbed(account_id, options \\ nil) do
    url = github_base() <> "/marketplace_listing/stubbed/accounts/#{account_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.MarketplacePurchase, options)
  end

  @doc """
  Get a user installation for the authenticated app

  @see https://docs.github.com/rest/apps/apps#get-a-user-installation-for-the-authenticated-app
  """
  def get_user_installation(username, options \\ nil) do
    url = github_base() <> "/users/#{username}/installation"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Installation, options)
  end

  @doc """
  Get a webhook configuration for an app

  @see https://docs.github.com/rest/apps/webhooks#get-a-webhook-configuration-for-an-app
  """
  def get_webhook_config_for_app(options \\ nil) do
    url = github_base() <> "/app/hook/config"
    body = %{}
    api_call(:get, url, body, Noizu.Github.WebhookConfig, options)
  end

  @doc """
  Get a delivery for an app webhook

  @see https://docs.github.com/rest/apps/webhooks#get-a-delivery-for-an-app-webhook
  """
  def get_webhook_delivery(delivery_id, options \\ nil) do
    url = github_base() <> "/app/hook/deliveries/#{delivery_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.HookDelivery, options)
  end

  @doc """
  List accounts for a plan

  @see https://docs.github.com/rest/apps/marketplace#list-accounts-for-a-plan
  """
  def list_accounts_for_plan(plan_id, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:sort, options, nil),
            get_field(:direction, options, nil),
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/marketplace_listing/plans/#{plan_id}/accounts" <> qs
      )

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

  @doc """
  List accounts for a plan (stubbed)

  @see https://docs.github.com/rest/apps/marketplace#list-accounts-for-a-plan-stubbed
  """
  def list_accounts_for_plan_stubbed(plan_id, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:sort, options, nil),
            get_field(:direction, options, nil),
            get_field(:per_page, options, nil),
            get_field(:page, options, nil)
          ]
          |> Enum.filter(& &1)

        qs = if query == [], do: "", else: "?" <> Enum.join(query, "&")
        github_base() <> "/marketplace_listing/stubbed/plans/#{plan_id}/accounts" <> qs
      )

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

  @doc """
  List repositories accessible to the user access token

  @see https://docs.github.com/rest/apps/installations#list-repositories-accessible-to-the-user-access-token
  """
  def list_installation_repos_for_authenticated_user(installation_id, 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/installations/#{installation_id}/repositories" <> qs
      )

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

  @doc """
  List installation requests for the authenticated app

  @see https://docs.github.com/rest/apps/apps#list-installation-requests-for-the-authenticated-app
  """
  def list_installation_requests_for_authenticated_app(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() <> "/app/installation-requests" <> qs
      )

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

  @doc """
  List installations for the authenticated app

  @see https://docs.github.com/rest/apps/apps#list-installations-for-the-authenticated-app
  """
  def list_installations(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:page, options, nil),
            get_field(:since, options, nil),
            get_field(:outdated, options, nil)
          ]
          |> Enum.filter(& &1)

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

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

  @doc """
  List app installations accessible to the user access token

  @see https://docs.github.com/rest/apps/installations#list-app-installations-accessible-to-the-user-access-token
  """
  def list_installations_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/installations" <> qs
      )

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

  @doc """
  List plans

  @see https://docs.github.com/rest/apps/marketplace#list-plans
  """
  def list_plans(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() <> "/marketplace_listing/plans" <> qs
      )

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

  @doc """
  List plans (stubbed)

  @see https://docs.github.com/rest/apps/marketplace#list-plans-stubbed
  """
  def list_plans_stubbed(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() <> "/marketplace_listing/stubbed/plans" <> qs
      )

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

  @doc """
  List repositories accessible to the app installation

  @see https://docs.github.com/rest/apps/installations#list-repositories-accessible-to-the-app-installation
  """
  def list_repos_accessible_to_installation(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() <> "/installation/repositories" <> qs
      )

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

  @doc """
  List subscriptions for the authenticated user

  @see https://docs.github.com/rest/apps/marketplace#list-subscriptions-for-the-authenticated-user
  """
  def list_subscriptions_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/marketplace_purchases" <> qs
      )

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

  @doc """
  List subscriptions for the authenticated user (stubbed)

  @see https://docs.github.com/rest/apps/marketplace#list-subscriptions-for-the-authenticated-user-stubbed
  """
  def list_subscriptions_for_authenticated_user_stubbed(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/marketplace_purchases/stubbed" <> qs
      )

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

  @doc """
  List deliveries for an app webhook

  @see https://docs.github.com/rest/apps/webhooks#list-deliveries-for-an-app-webhook
  """
  def list_webhook_deliveries(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:per_page, options, nil),
            get_field(:cursor, options, nil),
            get_field(:status, options, nil)
          ]
          |> Enum.filter(& &1)

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

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

  @doc """
  Redeliver a delivery for an app webhook

  @see https://docs.github.com/rest/apps/webhooks#redeliver-a-delivery-for-an-app-webhook
  """
  def redeliver_webhook_delivery(delivery_id, body, options \\ nil) do
    url = github_base() <> "/app/hook/deliveries/#{delivery_id}/attempts"
    body = body
    api_call(:post, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Remove a repository from an app installation

  @see https://docs.github.com/rest/apps/installations#remove-a-repository-from-an-app-installation
  """
  def remove_repo_from_installation_for_authenticated_user(
        installation_id,
        repository_id,
        options \\ nil
      ) do
    url = github_base() <> "/user/installations/#{installation_id}/repositories/#{repository_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Reset a token

  @see https://docs.github.com/rest/apps/oauth-applications#reset-a-token
  """
  def reset_token(client_id, body, options \\ nil) do
    url = github_base() <> "/applications/#{client_id}/token"
    body = body
    api_call(:patch, url, body, Noizu.Github.Authorization, options)
  end

  @doc """
  Revoke an installation access token

  @see https://docs.github.com/rest/apps/installations#revoke-an-installation-access-token
  """
  def revoke_installation_access_token(options \\ nil) do
    url = github_base() <> "/installation/token"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Create a scoped access token

  @see https://docs.github.com/rest/apps/apps#create-a-scoped-access-token
  """
  def scope_token(client_id, body, options \\ nil) do
    url = github_base() <> "/applications/#{client_id}/token/scoped"
    body = body
    api_call(:post, url, body, Noizu.Github.Authorization, options)
  end

  @doc """
  Suspend an app installation

  @see https://docs.github.com/rest/apps/apps#suspend-an-app-installation
  """
  def suspend_installation(installation_id, body, options \\ nil) do
    url = github_base() <> "/app/installations/#{installation_id}/suspended"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Unsuspend an app installation

  @see https://docs.github.com/rest/apps/apps#unsuspend-an-app-installation
  """
  def unsuspend_installation(installation_id, options \\ nil) do
    url = github_base() <> "/app/installations/#{installation_id}/suspended"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Update a webhook configuration for an app

  @see https://docs.github.com/rest/apps/webhooks#update-a-webhook-configuration-for-an-app
  """
  def update_webhook_config_for_app(body, options \\ nil) do
    url = github_base() <> "/app/hook/config"
    body = body
    api_call(:patch, url, body, Noizu.Github.WebhookConfig, options)
  end
end