Skip to main content

lib/api/structs/collection.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.Collection do
  @moduledoc """
  Generic list result. Wraps a bare array (or a `{total_count, items}` search
  envelope) of untyped items together with pagination links.
  """
  defstruct [:items, :complete, :total, :links]

  def from_json(json, headers \\ [])

  def from_json(list, headers) when is_list(list) do
    %__MODULE__{
      items: list,
      complete: true,
      total: length(list),
      links: Noizu.Github.extract_links(headers)
    }
  end

  def from_json(%{items: items} = env, headers) when is_list(items) do
    %__MODULE__{
      items: items,
      complete: !Map.get(env, :incomplete_results, false),
      total: Map.get(env, :total_count, length(items)),
      links: Noizu.Github.extract_links(headers)
    }
  end

  def from_json(other, headers) do
    %__MODULE__{items: other, links: Noizu.Github.extract_links(headers)}
  end
end