Skip to main content

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

  @doc """
  Check if a gist is starred

  @see https://docs.github.com/rest/gists/gists#check-if-a-gist-is-starred
  """
  def check_is_starred(gist_id, options \\ nil) do
    url = github_base() <> "/gists/#{gist_id}/star"
    body = %{}
    api_call(:get, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Create a gist

  @see https://docs.github.com/rest/gists/gists#create-a-gist
  """
  def create(body, options \\ nil) do
    url = github_base() <> "/gists"
    body = body
    api_call(:post, url, body, Noizu.Github.GistSimple, options)
  end

  @doc """
  Create a gist comment

  @see https://docs.github.com/rest/gists/comments#create-a-gist-comment
  """
  def create_comment(gist_id, body, options \\ nil) do
    url = github_base() <> "/gists/#{gist_id}/comments"
    body = body
    api_call(:post, url, body, Noizu.Github.GistComment, options)
  end

  @doc """
  Delete a gist

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

  @doc """
  Delete a gist comment

  @see https://docs.github.com/rest/gists/comments#delete-a-gist-comment
  """
  def delete_comment(gist_id, comment_id, options \\ nil) do
    url = github_base() <> "/gists/#{gist_id}/comments/#{comment_id}"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Fork a gist

  @see https://docs.github.com/rest/gists/gists#fork-a-gist
  """
  def fork(gist_id, body, options \\ nil) do
    url = github_base() <> "/gists/#{gist_id}/forks"
    body = body
    api_call(:post, url, body, Noizu.Github.BaseGist, options)
  end

  @doc """
  Get a gist

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

  @doc """
  Get a gist comment

  @see https://docs.github.com/rest/gists/comments#get-a-gist-comment
  """
  def get_comment(gist_id, comment_id, options \\ nil) do
    url = github_base() <> "/gists/#{gist_id}/comments/#{comment_id}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.GistComment, options)
  end

  @doc """
  Get a gist revision

  @see https://docs.github.com/rest/gists/gists#get-a-gist-revision
  """
  def get_revision(gist_id, sha, options \\ nil) do
    url = github_base() <> "/gists/#{gist_id}/#{sha}"
    body = %{}
    api_call(:get, url, body, Noizu.Github.GistSimple, options)
  end

  @doc """
  List gists for the authenticated user

  @see https://docs.github.com/rest/gists/gists#list-gists-for-the-authenticated-user
  """
  def list(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:since, 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() <> "/gists" <> qs
      )

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

  @doc """
  List gist comments

  @see https://docs.github.com/rest/gists/comments#list-gist-comments
  """
  def list_comments(gist_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() <> "/gists/#{gist_id}/comments" <> qs
      )

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

  @doc """
  List gist commits

  @see https://docs.github.com/rest/gists/gists#list-gist-commits
  """
  def list_commits(gist_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() <> "/gists/#{gist_id}/commits" <> qs
      )

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

  @doc """
  List gists for a user

  @see https://docs.github.com/rest/gists/gists#list-gists-for-a-user
  """
  def list_for_user(username, options \\ nil) do
    url =
      (
        query =
          [
            get_field(:since, 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}/gists" <> qs
      )

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

  @doc """
  List gist forks

  @see https://docs.github.com/rest/gists/gists#list-gist-forks
  """
  def list_forks(gist_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() <> "/gists/#{gist_id}/forks" <> qs
      )

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

  @doc """
  List public gists

  @see https://docs.github.com/rest/gists/gists#list-public-gists
  """
  def list_public(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:since, 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() <> "/gists/public" <> qs
      )

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

  @doc """
  List starred gists

  @see https://docs.github.com/rest/gists/gists#list-starred-gists
  """
  def list_starred(options \\ nil) do
    url =
      (
        query =
          [
            get_field(:since, 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() <> "/gists/starred" <> qs
      )

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

  @doc """
  Star a gist

  @see https://docs.github.com/rest/gists/gists#star-a-gist
  """
  def star(gist_id, body, options \\ nil) do
    url = github_base() <> "/gists/#{gist_id}/star"
    body = body
    api_call(:put, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Unstar a gist

  @see https://docs.github.com/rest/gists/gists#unstar-a-gist
  """
  def unstar(gist_id, options \\ nil) do
    url = github_base() <> "/gists/#{gist_id}/star"
    body = %{}
    api_call(:delete, url, body, Noizu.Github.Raw, options)
  end

  @doc """
  Update a gist

  @see https://docs.github.com/rest/gists/gists#update-a-gist
  """
  def update(gist_id, body, options \\ nil) do
    url = github_base() <> "/gists/#{gist_id}"
    body = body
    api_call(:patch, url, body, Noizu.Github.GistSimple, options)
  end

  @doc """
  Update a gist comment

  @see https://docs.github.com/rest/gists/comments#update-a-gist-comment
  """
  def update_comment(gist_id, comment_id, body, options \\ nil) do
    url = github_base() <> "/gists/#{gist_id}/comments/#{comment_id}"
    body = body
    api_call(:patch, url, body, Noizu.Github.GistComment, options)
  end
end