Tentacat Documentation

repository·master·Indexed 19 days ago

https://github.com/edgurgel/tentacat

A simple Elixir wrapper for the GitHub API providing structured access to resources including repositories, users, issues, pulls, organizations, and GitHub Apps. It supports both authenticated and unauthenticated clients, custom endpoints for GitHub Enterprise, and configurable JSON deserialization via Jason.

Tokens
10.5K
Snippets
93
Records
94
Agent score
66%

What's inside Tentacat

  1. Use Tentacat without authentication

    master

    If you do not provide a client struct, Tentacat will perform unauthenticated requests. Note that this limits the available API actions. When not using a client, call the module functions directly without passing a client argument as the first parameter.

    # Unauthenticated call
    Tentacat.Users.find("edgurgel")
  2. Enable GitHub API Preview features

    master

    To use GitHub API endpoints that are currently in a 'preview' state, you must include specific media type headers in your requests. You can set this globally in your configuration using the :extra_headers key.

    config :tentacat,
      extra_headers: [{"Accept", "application/vnd.github.MEDIA-TYPE+json"}]
  3. Create a Tentacat client

    master

    A %Tentacat.Client{} struct holds the endpoint information and authentication credentials. You can initialize it using several methods depending on your security requirements.

    # Using a personal access token (Recommended)
    client = Tentacat.Client.new(%{access_token: "YOUR_TOKEN"})
    
    # Using username and password (May not work with MFA)
    client = Tentacat.Client.new(%{user: "user", password: "password"})
    
    # Connecting to an alternative endpoint (e.g., GitHub Enterprise)
    client = Tentacat.Client.new(%{access_token: "TOKEN"}, "https://ghe.example.com/api/v3/")
  4. Configure JSON deserialization options

    master

    Tentacat allows you to pass options to the underlying JSON decoder (Jason). For example, to have JSON keys returned as Atoms instead of Strings, configure the :deserialization_options key in your application configuration.

    config :tentacat, :deserialization_options, [keys: :atoms]
  5. Configure Tentacat application options

    master

    You can configure global settings for Tentacat using the application environment. This is useful for setting default headers, pagination methods, or JSON decoding options.

    config :tentacat,
      deserialization_options: [],
      extra_headers: [],
      pagination: [],
      request_options: []
  6. Configure extra headers for GitHub Reviews API

    master

    The GitHub Reviews API is currently in a pre-release state. To use it, you must configure the extra_headers option in your application configuration to include the required Accept header.

    config :tentacat, :extra_headers, [{"Accept", "application/vnd.github.black-cat-preview+json"}]
  7. Call the GitHub API with a client

    master

    Once a client is created, pass it as the first argument to most Tentacat module functions to perform authenticated requests.

    # Get a user's profile information
    Tentacat.Users.find(client, "edgurgel")
    
    # Create a comment on an issue
    Tentacat.Issues.Comments.create("edgurgel", "tentacat", 72, %{"body" => "This is a comment created using the API"})
  8. Fetch User Information

    master

    You can retrieve information about a specific GitHub user using Tentacat.Users.find/2 (requires a client) or Tentacat.Users.find/1 (unauthenticated).

    Using a Client

    client = Tentacat.Client.new()
    {status, data, response} = Tentacat.Users.find(client, "username")

    Unauthenticated (No Client)

    {status, data, response} = Tentacat.Users.find("username")

    Returns a tuple containing the HTTP status code, the decoded JSON body, and the full %HTTPoison.Response{} struct.

    # Using a client
    client = Tentacat.Client.new()
    {200, data, _response} = Tentacat.Users.find(client, "edgurgel")
    
    # Without a client
    {200, data, _response} = Tentacat.Users.find("edgurgel")
  9. Initialize a Tentacat Client

    master

    Every GitHub API call requires a client. You can create an unauthenticated client for public requests or an authenticated client to avoid strict rate limits.

    Unauthenticated Client

    Use Tentacat.Client.new/0 to create a client with no authentication.

    Authenticated Client

    Pass an options map to Tentacat.Client.new/1 to provide credentials. Supported authentication methods include:

    • User and Password: %{user: "user", password: "password"}
    • Personal Access Token: %{access_token: "TOKEN"}

    You can also specify a custom endpoint (e.g., for GitHub Enterprise) as the second argument to Tentacat.Client.new/2.

    # Unauthenticated
    client = Tentacat.Client.new()
    
    # Authenticated with token
    client = Tentacat.Client.new(%{access_token: "928392873982932"})
    
    # Authenticated with custom endpoint
    client = Tentacat.Client.new(%{access_token: "TOKEN"}, "https://ghe.example.com/api/v3/")
    # Unauthenticated
    client = Tentacat.Client.new()
    
    # Authenticated with token
    client = Tentacat.Client.new(%{access_token: "928392873982932"})
    
    # Authenticated with custom endpoint
    client = Tentacat.Client.new(%{access_token: "928392873982932"}, "https://ghe.example.com/api/v3/")
  10. List Gists with Tentacat.Gists

    master

    Use Tentacat.Gists to retrieve lists of gists from various scopes:

    • list_mine(client, params \ [], options \ []): Lists the current authenticated user's gists.
    • list_users(client, owner, params \ [], options \ []): Lists gists belonging to a specific user (owner).
    • list_public(client, params \ [], options \ []): Lists all public gists. Note: This method defaults to pagination: :none in its options.
    • list_starred(client, params \ [], options \ []): Lists the authenticated user's starred gists. Note: This method defaults to pagination: :none in its options.
    # List current user's gists
    Tentacat.Gists.list_mine(client)
    
    # List gists for a specific user
    Tentacat.Gists.list_users(client, "steve")
    
    # List all public gists
    Tentacat.Gists.list_public(client)
    
    # List starred gists
    Tentacat.Gists.list_starred(client)