telegraph

package module
v0.0.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: May 18, 2023 License: MIT Imports: 14 Imported by: 0

README

@andatoshiki/telegraph-go

Go library for using Telegraph API.

Install

$ go get -u github.com/andatoshiki/telegraph-go
Sample codes

View examples using this API wrapper in ./samples/.

License

MIT

Documentation

Index

Constants

View Source
const (
	APIBaseURL = "https://api.telegra.ph"
)

constants

Variables

View Source
var Verbose bool // default: false

Verbose flag for logging

Functions

This section is empty.

Types

type APIResponse

type APIResponse struct {
	Ok    bool   `json:"ok"`
	Error string `json:"error,omitempty"`
}

APIResponse struct

type APIResponseAccount

type APIResponseAccount struct {
	APIResponse
	Result Account `json:"result,omitempty"`
}

APIResponseAccount struct

type APIResponsePage

type APIResponsePage struct {
	APIResponse
	Result Page `json:"result,omitempty"`
}

APIResponsePage struct

type APIResponsePageList

type APIResponsePageList struct {
	APIResponse
	Result PageList `json:"result,omitempty"`
}

APIResponsePageList struct

type APIResponsePageViews

type APIResponsePageViews struct {
	APIResponse
	Result PageViews `json:"result,omitempty"`
}

APIResponsePageViews struct

type Account

type Account struct {
	ShortName  string `json:"short_name"`
	AuthorName string `json:"author_name"`
	AuthorURL  string `json:"author_url"`

	AccessToken string `json:"access_token,omitempty"`
	AuthURL     string `json:"auth_url,omitempty"`
	PageCount   int    `json:"page_count,omitempty"`
}

Account type

http://telegra.ph/api#Account

type Client

type Client struct {
	AccessToken string
	Socks5Proxy string
}

Client struct

func Create

func Create(shortName, authorName, authorURL string, socks5Proxy string) (*Client, error)

Create creates a new Telegraph client.

func Load

func Load(accessToken string, socks5Proxy string) (*Client, error)

Load a Telegraph client with access token.

func (*Client) CreateAccount

func (c *Client) CreateAccount(shortName, authorName, authorURL string) (acc Account, err error)

CreateAccount creates a new Telegraph account.

shortName: 1-32 characters authorName: 0-128 characters (optional) authorURL: 0-512 characters (optional)

http://telegra.ph/api#createAccount

func (*Client) CreatePage

func (c *Client) CreatePage(title, authorName, authorURL string, content []Node, returnContent bool) (page Page, err error)

CreatePage creates a new Telegraph page.

title: 1-256 characters authorName: 0-128 characters (optional) authorURL: 0-512 characters (optional) content: Array of Node returnContent: return created Page object or not

http://telegra.ph/api#createPage

func (*Client) CreatePageWithHTML

func (c *Client) CreatePageWithHTML(title, authorName, authorURL, htmlContent string, returnContent bool) (page Page, err error)

CreatePageWithHTML creates a new page with HTML.

func (*Client) EditAccountInfo

func (c *Client) EditAccountInfo(shortName, authorName, authorURL string) (acc Account, err error)

EditAccountInfo updates information about a Telegraph account.

shortName: 1-32 characters authorName: 0-128 characters (optional) authorURL: 0-512 characters (optional)

http://telegra.ph/api#editAccountInfo

func (*Client) EditPage

func (c *Client) EditPage(path, title string, content []Node, authorName, authorURL string, returnContent bool) (page Page, err error)

EditPage edits an existing Telegraph page.

path: Path to the page title: 1-256 characters content: Array of Node authorName: 0-128 characters (optional) authorURL: 0-512 characters (optional) returnContent: return edited Page object or not

http://telegra.ph/api#editPage

func (*Client) GetAccountInfo

func (c *Client) GetAccountInfo(fields []string) (acc Account, err error)

GetAccountInfo fetches information about a Telegraph account.

fields: Available fields: "short_name", "author_name", "author_url", "auth_url", and "page_count" (default = ["short_name", "author_name", "author_url"])

http://telegra.ph/api#getAccountInfo

func (*Client) GetPage

func (c *Client) GetPage(path string, returnContent bool) (page Page, err error)

GetPage fetches a Telegraph page.

path: Path to the Telegraph page returnContent: return the Page object or not

http://telegra.ph/api#getPage

func (*Client) GetPageList

func (c *Client) GetPageList(offset, limit int) (list PageList, err error)

GetPageList fetches a list of pages belonging to a Telegraph account.

offset: Sequential number of the first page (default = 0) limit: Number of pages to be returned (0-200, default = 50)

http://telegra.ph/api#getPageList

func (*Client) GetViews

func (c *Client) GetViews(path string, year, month, day, hour int) (views PageViews, err error)

GetViews fetches the number of views for a Telegraph page.

path: Path to the Telegraph page year: 2000-2100 (required when 'month' is passed) month: 1-12 (required when 'day' is passed) day: 1-31 (required when 'hour' is passed) hour: 0-24 (pass -1 if none)

http://telegra.ph/api#getViews

func (*Client) RevokeAccessToken

func (c *Client) RevokeAccessToken() (acc Account, err error)

RevokeAccessToken revokes access token and generate a new one.

http://telegra.ph/api#revokeAccessToken

type Node

type Node interface{} // XXX - can be a string, or NodeElement

Node type

http://telegra.ph/api#Node

func NewNodeWithElement

func NewNodeWithElement(tag string, attrs map[string]string, children []Node) Node

NewNodeWithElement creates a new node with given element.

func NewNodeWithString

func NewNodeWithString(str string) Node

NewNodeWithString creates a new node with given string.

func NewNodesWithHTML

func NewNodesWithHTML(html string) ([]Node, error)

NewNodesWithHTML creates new nodes with given HTML string.

type NodeElement

type NodeElement struct {
	Tag      string            `json:"tag"`
	Attrs    map[string]string `json:"attrs,omitempty"`
	Children []Node            `json:"children,omitempty"`
}

NodeElement type

http://telegra.ph/api#NodeElement

type Page

type Page struct {
	Path        string `json:"path"`
	URL         string `json:"url"`
	Title       string `json:"title"`
	Description string `json:"description"`
	AuthorName  string `json:"author_name,omitempty"`
	AuthorURL   string `json:"author_url,omitempty"`
	ImageURL    string `json:"image_url,omitempty"`
	Content     []Node `json:"content,omitempty"`
	Views       int    `json:"views"`
	CanEdit     bool   `json:"can_edit,omitempty"`
}

Page type

http://telegra.ph/api#Page

type PageList

type PageList struct {
	TotalCount int    `json:"total_count"`
	Pages      []Page `json:"pages"`
}

PageList type

http://telegra.ph/api#PageList

type PageViews

type PageViews struct {
	Views int `json:"views"`
}

PageViews type

http://telegra.ph/api#PageViews

Directories

Path Synopsis
samples

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL