Skip to content

Telegraph API Golang Client - A Go client library for the Telegra.ph API, providing a simple interface for creating and managing Telegraph articles programmatically.

License

Notifications You must be signed in to change notification settings

smirnoffmg/telegraph

Repository files navigation

Telegraph API Client in Go

Go License Build Status codecov

This repository contains a Go client library for the Telegraph API. Telegraph is a publishing tool that allows you to create formatted posts with rich media, and this client enables developers to interact programmatically with the Telegraph API.

Features

  • Account Management: Create and manage Telegraph accounts.
  • Page Management: Create, edit, and retrieve Telegraph pages.
  • Statistics: Retrieve view statistics for Telegraph pages.
  • Customizable: Easy to extend and customize for specific needs.
  • Debug Mode: Enable detailed logging for debugging purposes.
  • HTML Support: Create pages directly from HTML content.

Installation

To install the package, use the following command:

go get github.com/smirnoffmg/telegraph

Usage

Creating a New Account

Here's a simple example of how to create a new Telegraph account:

package main

import (
    "fmt"
    "log"
    "net/http"
    "time"

    "github.com/smirnoffmg/telegraph"
)

func main() {
    httpClient := &http.Client{
        Timeout: time.Second * 10,
    }
    client := telegraph.NewClient(httpClient)
    client.SetDebug(true)

    account, err := client.CreateAccount("Test", "Tester", "https://example.com")
    if err != nil {
        log.Fatalf("Failed to create account: %v", err)
    }
    fmt.Printf("Created account: %+v\n", account)
}

Other Operations

Get Account Information

accountInfo, err := client.GetAccountInfo(account.AccessToken, []string{"short_name", "author_name", "author_url", "page_count"})
if err != nil {
    log.Fatalf("Failed to get account info: %v", err)
}
fmt.Printf("Account info: %+v\n", accountInfo)

Create a Page

htmlContent := "<h3>Hello, world!</h3>"
page, err := client.CreatePage(account.AccessToken, "Test Page", htmlContent, "Tester", "https://example.com")
if err != nil {
    log.Fatalf("Failed to create page: %v", err)
}
fmt.Printf("Created page: %+v\n", page)

More Examples

For more examples on how to use this client, please refer to the examples directory.

Testing

This project uses pre-commit hooks to ensure code quality and consistency. To set up pre-commit hooks, run:

pip install pre-commit
pre-commit install

To run tests:

go test ./...

Contributing

Contributions are welcome! Please open an issue or submit a pull request for any changes or enhancements. Make sure to run pre-commit and tests before submitting your pull request.

License

This project is licensed under the MIT License. See the LICENSE file for details.

About

Telegraph API Golang Client - A Go client library for the Telegra.ph API, providing a simple interface for creating and managing Telegraph articles programmatically.

Topics

Resources

License

Code of conduct

Stars

Watchers

Forks

Packages

No packages published

Languages