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.
- 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.
To install the package, use the following command:
go get github.com/smirnoffmg/telegraph
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)
}
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)
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)
For more examples on how to use this client, please refer to the examples directory.
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 ./...
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.
This project is licensed under the MIT License. See the LICENSE file for details.