oschina

package
v0.5.2 Latest Latest
Warning

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

Go to latest
Published: Feb 14, 2022 License: MIT Imports: 15 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ArticleTypeOriginal ArticleType = "1" // 原创
	ArticleTypeReship   ArticleType = "4" // 转载

	ContentTypeMarkdown = "3"
	ContentTypeHTML     = "4"
)
View Source
const ArticleURLFormat = "https://my.oschina.net/%s/blog/%s"

Variables

This section is empty.

Functions

func DefaultHandler

func DefaultHandler(r *http.Response) (string, error)

func WriteBack added in v0.4.0

func WriteBack(saveType SaveType, mark *markdown.Mark, params *ContentParams, isCreate bool) error

Types

type Article added in v0.3.0

type Article struct {
	ID    string
	Title string
	URL   string
}

type ArticleType added in v0.3.0

type ArticleType string

type Category added in v0.3.0

type Category struct {
	ID   string
	Name string
}

type Client

type Client struct {
	BaseURL  string
	Cookie   string
	UserCode string
	UserID   string
	SpaceID  string
	UserName string
}

func NewClient

func NewClient(cookie string) (*Client, error)

func (*Client) AddCategory

func (c *Client) AddCategory(name string) error

AddCategory add a new category

func (*Client) BuildArticleURL added in v0.3.0

func (c *Client) BuildArticleURL(id string) string

func (*Client) BuildDraftEditorURL added in v0.4.0

func (c *Client) BuildDraftEditorURL(id string) string

func (*Client) BuildURL added in v0.3.0

func (c *Client) BuildURL(path string) string

func (*Client) DeleteArticle

func (c *Client) DeleteArticle(id string) error

func (*Client) DeleteDraft added in v0.3.0

func (c *Client) DeleteDraft(id string) error

func (*Client) Get

func (c *Client) Get(rawurl string, params *url.Values, handler func(r *http.Response) (string, error)) (string, error)

Get request with GET method and support response handler

func (*Client) GetCategoryByName added in v0.3.0

func (c *Client) GetCategoryByName(name string) (*Category, error)

func (*Client) GetDraftDetail added in v0.3.0

func (c *Client) GetDraftDetail(id string) (*ContentParams, error)

func (*Client) GetTechnicalFieldByName added in v0.3.0

func (c *Client) GetTechnicalFieldByName(name string) (*TechnicalField, error)

func (*Client) ListArticles added in v0.2.0

func (c *Client) ListArticles(page int, keyword string) (articles []*Article, hasNext bool, err error)

func (*Client) ListCategories added in v0.3.0

func (c *Client) ListCategories() ([]*Category, error)

ListCategories list all categories

func (*Client) ListDrafts added in v0.3.0

func (c *Client) ListDrafts(page int) (drafts []*Draft, hasNext bool, err error)

func (*Client) ListTechnicalFields added in v0.3.0

func (c *Client) ListTechnicalFields() ([]*TechnicalField, error)

ListTechnicalFields list all technical fields

func (*Client) ParseMark added in v0.4.0

func (c *Client) ParseMark(mark *markdown.Mark) (*ContentParams, error)

func (*Client) Post

func (c *Client) Post(path string, values url.Values, handler func(r *http.Response) (string, error)) (string, error)

func (*Client) PublishDraft added in v0.3.0

func (c *Client) PublishDraft(id string) (articleID string, err error)

func (*Client) SaveArticle

func (c *Client) SaveArticle(params *ContentParams) error

SaveArticle create an article if id is empty, otherwise update existed article.

func (*Client) SaveDraft

func (c *Client) SaveDraft(params *ContentParams) error

SaveDraft create a new draft if id is empty, otherwise update draft

type ContentParams added in v0.3.0

type ContentParams struct {
	ID             string      `url:"id"`           // 文章 ID
	DraftID        string      `url:"draft"`        // 草稿 ID
	Title          string      `url:"title"`        // 文章标题
	Content        string      `url:"content"`      // 文章内容
	Category       string      `url:"catalog"`      // 文章分类
	TechnicalField string      `url:"groups"`       // 技术领域,草稿无法设置
	OriginalURL    string      `url:"origin_url"`   // 原文链接
	Privacy        int         `url:"privacy"`      // 仅自己可见
	DenyComment    int         `url:"deny_comment"` // 禁止评论
	Top            int         `url:"as_top"`       // 置顶
	DownloadImage  int         `url:"downloadImg"`  // 下载外站图片
	Type           ArticleType `url:"type"`         // 原创、转载
	ContentType    string      `url:"content_type"`
	PublishAsBlog  int         `url:"publish_as_blog"`
}

func (*ContentParams) Validate added in v0.3.0

func (p *ContentParams) Validate() error

type Draft added in v0.3.0

type Draft struct {
	ID    string
	Title string
	URL   string
}

type MarkdownOptions

type MarkdownOptions struct {
	Publish       bool   `yaml:"publish"`
	Title         string `yaml:"title"`
	Category      string `yaml:"category"`
	Field         string `yaml:"field"`
	OriginURL     string `yaml:"origin_url"`
	Original      bool   `yaml:"original"`
	Privacy       bool   `yaml:"privacy"`
	DownloadImage bool   `yaml:"download_image"`
	Top           bool   `yaml:"top"`
	DenyComment   bool   `yaml:"deny_comment"`
}

type SaveType added in v0.4.0

type SaveType string
const (
	SaveTypeArticle SaveType = "article"
	SaveTypeDraft   SaveType = "draft"
)

type TechnicalField added in v0.3.0

type TechnicalField struct {
	ID   string
	Name string
}

Jump to

Keyboard shortcuts

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