docbase

package module
v0.0.0-...-978ba50 Latest Latest
Warning

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

Go to latest
Published: Mar 15, 2022 License: MIT Imports: 15 Imported by: 2

README

go-docbase

DocBase API Go言語向け クライアントライブラリ

Installation

このパッケージは、go getコマンドでインストールできます:

go get github.com/micheam/go-docbase

go doc コマンドからドキュメントを参照してください:

go doc github.com/micheam/go-docbase

Usage

記事の一覧抽出:

var (
    ctx    = context.Background()
    domain = os.Getenv("DOCBASE_DOMAIN")
    param  = url.Values{}
)
docbase.SetToken(os.Getenv("DOCBASE_TOKEN"))
posts, meta, _ := docbase.ListPosts(ctx, domain, param)
for i := range posts {
 e   fmt.Println(posts[i].Title)
}

記事詳細の取得:

var (
    ctx    = context.Background()
    domain = os.Getenv("DOCBASE_DOMAIN")
    postID = docbase.PostID(1863830) // 記事ID
)
docbase.SetToken(os.Getenv("DOCBASE_TOKEN"))
post, _ := docbase.GetPost(ctx, domain, postID)
fmt.Printf("%d:%s\n%s", post.ID, post.Title, post.Body)

その他の例については、 examples を参照してみてください。

TODO

API Method Endpoint
所属チーム取得API https://help.docbase.io/posts/92977
ユーザ検索API https://help.docbase.io/posts/680809
メモの検索API https://help.docbase.io/posts/92984
メモの投稿API https://help.docbase.io/posts/92980
メモの詳細取得API https://help.docbase.io/posts/97204
メモの更新API https://help.docbase.io/posts/92981
メモのアーカイブAPI https://help.docbase.io/posts/665804
メモのアーカイブ解除API https://help.docbase.io/posts/665806
メモの削除API https://help.docbase.io/posts/92982
コメント投稿API https://help.docbase.io/posts/216289
コメント削除API https://help.docbase.io/posts/216290
ファイルアップロードAPI https://help.docbase.io/posts/225804
ファイルダウンロードAPI https://help.docbase.io/posts/1084833
タグの取得API https://help.docbase.io/posts/92979
グループ作成API https://help.docbase.io/posts/652985
グループ検索API https://help.docbase.io/posts/92978
グループ詳細取得API https://help.docbase.io/posts/652983
グループへのユーザー追加API https://help.docbase.io/posts/665797
グループからユーザーを削除するAPI https://help.docbase.io/posts/665799

License

MIT

Author

micheam michto.maeda@gmail.com

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ListPosts

func ListPosts(ctx context.Context, domain string, param url.Values) ([]Post, *Meta, error)

func SetToken

func SetToken(t string)

Types

type Client

type Client struct {
	*http.Client
	// contains filtered or unexported fields
}

func (*Client) GetPost

func (c *Client) GetPost(ctx context.Context, domain string, id PostID) (*Post, error)

func (*Client) ListPosts

func (c *Client) ListPosts(ctx context.Context, domain string, param url.Values) ([]Post, *Meta, error)

func (*Client) ListTags

func (c *Client) ListTags(ctx context.Context, domain string) ([]Tag, error)

func (*Client) NewPost

func (c *Client) NewPost(ctx context.Context, domain string, title string, body io.Reader, option PostOption) (*Post, error)

func (*Client) NewRequest

func (c *Client) NewRequest(ctx context.Context, method, _url string, body io.Reader, param *url.Values) (*http.Request, error)

func (*Client) UpdatePost

func (c *Client) UpdatePost(ctx context.Context, domain string, id PostID, body io.Reader, fields UpdateFields) (*Post, error)

type Criteria

type Criteria struct {
	Keywords []string
	Include  map[string][]interface{}
	Exclude  map[string][]interface{}
}

Criteria は、検索時の絞り込みオプションを定義する。

Notes:

指定可能なキーについては、 docbase 公式のオプションを参照してください。 https://help.docbase.io/posts/59432?list=%2Fsearch&q=%E6%A4%9C%E7%B4%A2#%E6%A4%9C%E7%B4%A2%E3%82%AA%E3%83%97%E3%82%B7%E3%83%A7%E3%83%B3

なお、Version 1.0 現在、`OR検索` には対応していません。

func (*Criteria) MarshalText

func (c *Criteria) MarshalText() (text []byte, err error)

type Meta

type Meta struct {
	PreviousPageURL string `json:"previous_page"`
	NextPageURL     string `json:"next_page"`
	Total           int    `json:"total"`
}

type Post

type Post struct {
	ID         PostID        `json:"id"`
	Title      string        `json:"title"`
	Body       string        `json:"body"`
	Draft      bool          `json:"draft"`
	Archived   bool          `json:"archived"`
	URL        string        `json:"url"`
	CreatedAt  string        `json:"created_at"` // ISO 8601
	UpdatedAt  string        `json:"updated_at"` // ISO 8601
	Scope      Scope         `json:"scope"`
	SharingURL string        `json:"sharing_url"`
	Tags       []Tag         `json:"tags"`
	User       User          `json:"user"`
	Stars      int           `json:"stars_count"`
	GoodJob    int           `json:"good_jobs_count"`
	Comments   []interface{} `json:"comments"`
	Groups     []interface{} `json:"groups"`
}

func GetPost

func GetPost(ctx context.Context, domain string, id PostID) (*Post, error)

func NewPost

func NewPost(ctx context.Context, domain string, title string, body io.Reader, option PostOption) (*Post, error)

func UpdatePost

func UpdatePost(ctx context.Context, domain string, id PostID, body io.Reader, fields UpdateFields) (*Post, error)

type PostID

type PostID int

func ParsePostID

func ParsePostID(s string) (PostID, error)

func (PostID) Int

func (p PostID) Int() int

func (PostID) String

func (p PostID) String() string

type PostOption

type PostOption struct {
	Draft  *bool    `json:"draft,omitempty"`
	Notice *bool    `json:"notice,omitempty"`
	Tags   []string `json:"tags"`
	Scope  string   `json:"scope,omitempty"` // TODO(micheam): 指定可能な値を明示する everyon (default), group, private
	Groups []int    `json:"groups"`          // require on scope:groups
}

type Scope

type Scope string
const (
	ScopeEveryone Scope = "everyone"
	ScopeGroup    Scope = "group"
	ScopePrivate  Scope = "private"
)

type Tag

type Tag struct {
	Name string `json:"name"`
}

func ListTags

func ListTags(ctx context.Context, domain string) ([]Tag, error)

type UpdateFields

type UpdateFields struct {
	Title  *string   `json:"title,omitempty"`
	Draft  *bool     `json:"draft,omitempty"`
	Notice *bool     `json:"notice,omitempty"`
	Tags   *[]string `json:"tags,omitempty"`
	Scope  *string   `json:"scope,omitempty"`
	Groups *[]int    `json:"groups,omitempty"`
}

UpdateFields は、更新対象のフィールドを保持します。

type User

type User struct {
	ID              UserID `json:"id"`
	Name            string `json:"name"`
	ProfileImageURL string `json:"profile_image_url"`
}

type UserID

type UserID int

Directories

Path Synopsis
examples
get-post command
list-posts command

Jump to

Keyboard shortcuts

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