Skip to main content

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

  @doc """
  Check if a repository is starred by the authenticated user

  @see https://docs.github.com/rest/activity/starring#check-if-a-repository-is-starred-by-the-authenticated-user
  """
  def check_repo_is_starred_by_authenticated_user(options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)
    url = github_base() <> "/user/starred/#{owner}/#{repo}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete a repository subscription

  @see https://docs.github.com/rest/activity/watching#delete-a-repository-subscription
  """
  def delete_repo_subscription(options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)
    url = github_base() <> "/repos/#{owner}/#{repo}/subscription"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Delete a thread subscription

  @see https://docs.github.com/rest/activity/notifications#delete-a-thread-subscription
  """
  def delete_thread_subscription(thread_id, options \\ nil) do
    url = github_base() <> "/notifications/threads/#{thread_id}/subscription"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Get feeds

  @see https://docs.github.com/rest/activity/feeds#get-feeds
  """
  def get_feeds(options \\ nil) do
    url = github_base() <> "/feeds"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Feed, options)
  end

  @doc """
  Get a repository subscription

  @see https://docs.github.com/rest/activity/watching#get-a-repository-subscription
  """
  def get_repo_subscription(options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)
    url = github_base() <> "/repos/#{owner}/#{repo}/subscription"
    body = %{}
    api_call(:get, url, body, Noizu.Github.RepositorySubscription, options)
  end

  @doc """
  Get a thread

  @see https://docs.github.com/rest/activity/notifications#get-a-thread
  """
  def get_thread(thread_id, options \\ nil) do
    url = github_base() <> "/notifications/threads/#{thread_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Thread, options)
  end

  @doc """
  Get a thread subscription for the authenticated user

  @see https://docs.github.com/rest/activity/notifications#get-a-thread-subscription-for-the-authenticated-user
  """
  def get_thread_subscription_for_authenticated_user(thread_id, options \\ nil) do
    url = github_base() <> "/notifications/threads/#{thread_id}/subscription"
    body = %{}
    api_call(:get, url, body, Noizu.Github.ThreadSubscription, options)
  end

  @doc """
  List events for the authenticated user

  @see https://docs.github.com/rest/activity/events#list-events-for-the-authenticated-user
  """
  def list_events_for_authenticated_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}/events" <> qs
      )

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

  @doc """
  List notifications for the authenticated user

  @see https://docs.github.com/rest/activity/notifications#list-notifications-for-the-authenticated-user
  """
  def list_notifications_for_authenticated_user(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:all, options, nil),
            get_field(:participating, options, nil),
            get_field(:since, options, nil),
            get_field(:before, options, nil),
            get_field(:page, options, nil),
            get_field(:per_page, options, nil)
          ]
          |> Enum.filter(& &1)

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

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

  @doc """
  List organization events for the authenticated user

  @see https://docs.github.com/rest/activity/events#list-organization-events-for-the-authenticated-user
  """
  def list_org_events_for_authenticated_user(username, org, 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}/events/orgs/#{org}" <> qs
      )

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

  @doc """
  List public events

  @see https://docs.github.com/rest/activity/events#list-public-events
  """
  def list_public_events(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() <> "/events" <> qs
      )

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

  @doc """
  List public events for a network of repositories

  @see https://docs.github.com/rest/activity/events#list-public-events-for-a-network-of-repositories
  """
  def list_public_events_for_repo_network(options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)

    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() <> "/networks/#{owner}/#{repo}/events" <> qs
      )

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

  @doc """
  List public events for a user

  @see https://docs.github.com/rest/activity/events#list-public-events-for-a-user
  """
  def list_public_events_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}/events/public" <> qs
      )

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

  @doc """
  List public organization events

  @see https://docs.github.com/rest/activity/events#list-public-organization-events
  """
  def list_public_org_events(org, 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() <> "/orgs/#{org}/events" <> qs
      )

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

  @doc """
  List events received by the authenticated user

  @see https://docs.github.com/rest/activity/events#list-events-received-by-the-authenticated-user
  """
  def list_received_events_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}/received_events" <> qs
      )

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

  @doc """
  List public events received by a user

  @see https://docs.github.com/rest/activity/events#list-public-events-received-by-a-user
  """
  def list_received_public_events_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}/received_events/public" <> qs
      )

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

  @doc """
  List repository events

  @see https://docs.github.com/rest/activity/events#list-repository-events
  """
  def list_repo_events(options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)

    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() <> "/repos/#{owner}/#{repo}/events" <> qs
      )

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

  @doc """
  List repository notifications for the authenticated user

  @see https://docs.github.com/rest/activity/notifications#list-repository-notifications-for-the-authenticated-user
  """
  def list_repo_notifications_for_authenticated_user(options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)

    url =
      (
        query =
          [
            get_field(:all, options, nil),
            get_field(:participating, options, nil),
            get_field(:since, options, nil),
            get_field(:before, 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() <> "/repos/#{owner}/#{repo}/notifications" <> qs
      )

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

  @doc """
  List repositories starred by the authenticated user

  @see https://docs.github.com/rest/activity/starring#list-repositories-starred-by-the-authenticated-user
  """
  def list_repos_starred_by_authenticated_user(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() <> "/user/starred" <> qs
      )

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

  @doc """
  List repositories starred by a user

  @see https://docs.github.com/rest/activity/starring#list-repositories-starred-by-a-user
  """
  def list_repos_starred_by_user(username, 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() <> "/users/#{username}/starred" <> qs
      )

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

  @doc """
  List repositories watched by a user

  @see https://docs.github.com/rest/activity/watching#list-repositories-watched-by-a-user
  """
  def list_repos_watched_by_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}/subscriptions" <> qs
      )

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

  @doc """
  List stargazers

  @see https://docs.github.com/rest/activity/starring#list-stargazers
  """
  def list_stargazers_for_repo(options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)

    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() <> "/repos/#{owner}/#{repo}/stargazers" <> qs
      )

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

  @doc """
  List repositories watched by the authenticated user

  @see https://docs.github.com/rest/activity/watching#list-repositories-watched-by-the-authenticated-user
  """
  def list_watched_repos_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/subscriptions" <> qs
      )

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

  @doc """
  List watchers

  @see https://docs.github.com/rest/activity/watching#list-watchers
  """
  def list_watchers_for_repo(options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)

    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() <> "/repos/#{owner}/#{repo}/subscribers" <> qs
      )

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

  @doc """
  Mark notifications as read

  @see https://docs.github.com/rest/activity/notifications#mark-notifications-as-read
  """
  def mark_notifications_as_read(body, options \\ nil) do
    url = github_base() <> "/notifications"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Mark repository notifications as read

  @see https://docs.github.com/rest/activity/notifications#mark-repository-notifications-as-read
  """
  def mark_repo_notifications_as_read(body, options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)
    url = github_base() <> "/repos/#{owner}/#{repo}/notifications"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Mark a thread as done

  @see https://docs.github.com/rest/activity/notifications#mark-a-thread-as-done
  """
  def mark_thread_as_done(thread_id, options \\ nil) do
    url = github_base() <> "/notifications/threads/#{thread_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Mark a thread as read

  @see https://docs.github.com/rest/activity/notifications#mark-a-thread-as-read
  """
  def mark_thread_as_read(thread_id, body, options \\ nil) do
    url = github_base() <> "/notifications/threads/#{thread_id}"
    body = body
    api_call(:patch, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Set a repository subscription

  @see https://docs.github.com/rest/activity/watching#set-a-repository-subscription
  """
  def set_repo_subscription(body, options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)
    url = github_base() <> "/repos/#{owner}/#{repo}/subscription"
    body = body
    api_call(:put, url, body, Noizu.Github.RepositorySubscription, options)
  end

  @doc """
  Set a thread subscription

  @see https://docs.github.com/rest/activity/notifications#set-a-thread-subscription
  """
  def set_thread_subscription(thread_id, body, options \\ nil) do
    url = github_base() <> "/notifications/threads/#{thread_id}/subscription"
    body = body
    api_call(:put, url, body, Noizu.Github.ThreadSubscription, options)
  end

  @doc """
  Star a repository for the authenticated user

  @see https://docs.github.com/rest/activity/starring#star-a-repository-for-the-authenticated-user
  """
  def star_repo_for_authenticated_user(body, options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)
    url = github_base() <> "/user/starred/#{owner}/#{repo}"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Unstar a repository for the authenticated user

  @see https://docs.github.com/rest/activity/starring#unstar-a-repository-for-the-authenticated-user
  """
  def unstar_repo_for_authenticated_user(options \\ nil) do
    owner = repo_owner(options)
    repo = repo_name(options)
    url = github_base() <> "/user/starred/#{owner}/#{repo}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end
end