telegraph/edit_page.go

52 lines
1.3 KiB
Go
Raw Normal View History

2017-09-04 21:09:59 +00:00
package telegraph
import (
"strconv"
json "github.com/pquerna/ffjson/ffjson"
http "github.com/valyala/fasthttp"
)
// EditPage edit an existing Telegraph page. On success, returns a Page object.
2017-09-04 21:09:59 +00:00
func (account *Account) EditPage(update *Page, returnContent bool) (*Page, error) {
args := http.AcquireArgs()
2017-09-04 21:09:59 +00:00
// Access token of the Telegraph account.
args.Add("access_token", account.AccessToken) // required
// Page title.
args.Add("title", update.Title) // required
if update.AuthorName != "" {
// Author name, displayed below the article's title.
args.Add("author_name", update.AuthorName)
}
if update.AuthorURL != "" {
// Profile link, opened when users click on the author's name below the title. Can be any
// link, not necessarily to a Telegram profile or channel.
2017-09-04 21:09:59 +00:00
args.Add("author_url", update.AuthorURL)
}
// If true, a content field will be returned in the Page object.
args.Add("return_content", strconv.FormatBool(returnContent))
content, err := json.Marshal(update.Content)
if err != nil {
return nil, err
}
// Content of the page.
args.Add("content", string(content)) // required
body, err := request("editPage", update.Path, args)
2017-09-04 21:09:59 +00:00
if err != nil {
return nil, err
}
var resp Page
err = json.Unmarshal(*body.Result, &resp)
return &resp, err
}