telegraph

package module
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2021 License: MIT Imports: 14 Imported by: 0

README

Telegraph Go

Golang Telegraph API SDK.

Guide

Installation
go get github.com/frontware/telegraph-go
Example
package main

import (
	"fmt"
	"github.com/frontware/telegraph-go"
	log "github.com/sirupsen/logrus"
)

func main() {
	client, err := telegraph.NewClient("", nil)
	if err != nil {
		log.Panicln(err)
	}
	account, err := client.CreateAccount("telegraph-go", &telegraph.CreateAccountOption{
		AuthorName: "TelegraphGo",
		AuthorURL:  "https://github.com/kallydev",
	})
	if err != nil {
		log.Panicln(err)
	}
	client.AccessToken = account.AccessToken
	paths, err := client.Upload([]string{
		"public/banner.png",
	})
	if err != nil {
		log.Panicln(err)
	}
	page, err := client.CreatePage("Telegraph-Go Example", []telegraph.Node{
		telegraph.NodeElement{
			Tag: "p",
			Children: []telegraph.Node{
				"hello world",
				telegraph.NodeElement{
					Tag: "img",
					Attrs: map[string]string{
						"src":  paths[0],
						"alt": "Banner",
					},
				},
			},
		},
	}, &telegraph.CreatePageOption{
		ReturnContent: true,
	})
	if err != nil {
		log.Panicln(err)
	}
	fmt.Println(page)
}

License

Copyright (c) KallyDev. All rights reserved.

Licensed under the MIT license.

Documentation

Index

Constants

View Source
const (
	FieldShortName  = "short_name"
	FieldAuthorName = "author_name"
	FieldAuthorURL  = "author_url"
	FieldAuthURL    = "auth_url"
	FieldPageCount  = "page_count"
)

Variables

This section is empty.

Functions

This section is empty.

Types

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"`
}

type Client

type Client struct {
	AccessToken string
	// contains filtered or unexported fields
}

Client represents the connection to Telegra.ph API.

func NewClient

func NewClient(accessToken string, option *ClientOption) (client *Client, err error)

NewClient returns a new connection to Telegra.ph API.s

func (*Client) CreateAccount

func (client *Client) CreateAccount(shortName string, option *CreateAccountOption) (account *Account, err error)

func (*Client) CreatePage

func (client *Client) CreatePage(title string, content []Node, option *CreatePageOption) (page *Page, err error)

func (*Client) EditAccountInfo

func (client *Client) EditAccountInfo(option *EditAccountInfoOption) (account *Account, err error)

func (*Client) EditPage

func (client *Client) EditPage(path, title string, content []Node, option *EditPageOption) (page *Page, err error)

func (*Client) GetAccountInfo

func (client *Client) GetAccountInfo(option *GetAccountInfoOption) (account *Account, err error)

func (*Client) GetPage

func (client *Client) GetPage(path string, option *GetPageOption) (page *Page, err error)

func (*Client) GetPageList

func (client *Client) GetPageList(option *GetPageListOption) (pageList *PageList, err error)

func (*Client) GetViews

func (client *Client) GetViews(path string, year, month, day int, option *GetViewsOption) (pageViews *PageViews, err error)

func (*Client) RevokeAccessToken

func (client *Client) RevokeAccessToken() (account *Account, err error)

func (*Client) Upload

func (client *Client) Upload(filenames []string) (paths []string, err error)

type ClientOption

type ClientOption struct {
	Proxy   string
	Timeout time.Duration
}

type CreateAccountOption

type CreateAccountOption struct {
	AuthorName string
	AuthorURL  string
}

type CreatePageOption

type CreatePageOption struct {
	AuthorName    string
	AuthorURL     string
	ReturnContent bool
}

type EditAccountInfoOption

type EditAccountInfoOption struct {
	ShortName  string
	AuthorName string
	AuthorURL  string
}

type EditPageOption

type EditPageOption struct {
	AuthorName    string
	AuthorURL     string
	ReturnContent bool
}

type GetAccountInfoOption

type GetAccountInfoOption struct {
	Fields []string
}

type GetPageListOption

type GetPageListOption struct {
	Offset int
	Limit  int
}

type GetPageOption

type GetPageOption struct {
	ReturnContent bool
}

type GetViewsOption

type GetViewsOption struct {
	Hour int
}

type Node

type Node interface{}

func ContentFormat added in v1.0.2

func ContentFormat(data interface{}) (n []Node, err error)

ContentFormat transforms data to a DOM-based format to represent the content of the page.

type NodeElement

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

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,omitempty"`
	CanEdit     bool   `json:"can_edit,omitempty"`
}

type PageList

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

type PageViews

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

Jump to

Keyboard shortcuts

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