telegraph/edit_page.go

36 lines
933 B
Go
Raw Normal View History

2017-09-04 21:09:59 +00:00
package telegraph
import (
2018-07-27 11:51:14 +00:00
"path"
2017-09-04 21:09:59 +00:00
"strconv"
http "github.com/valyala/fasthttp"
)
// EditPage edit an existing Telegraph page. On success, returns a Page object.
2019-07-24 08:03:29 +00:00
func (a *Account) EditPage(update Page, returnContent bool) (*Page, error) {
src, err := parser.Marshal(update.Content)
2017-09-04 21:09:59 +00:00
if err != nil {
2019-07-24 08:03:29 +00:00
return nil, err
2017-09-04 21:09:59 +00:00
}
2018-07-27 11:51:14 +00:00
args := http.AcquireArgs()
defer http.ReleaseArgs(args)
args.Add("access_token", a.AccessToken) // required
args.Add("path", update.Path) // required
args.Add("title", update.Title) // required
2019-07-24 08:03:29 +00:00
args.AddBytesV("content", src) // required
args.Add("author_name", update.AuthorName)
args.Add("author_url", update.AuthorURL)
2018-07-27 11:51:14 +00:00
args.Add("return_content", strconv.FormatBool(returnContent))
2017-09-04 21:09:59 +00:00
2019-07-24 08:03:29 +00:00
data, err := makeRequest(path.Join("editPage", update.Path), args)
2017-09-04 21:09:59 +00:00
if err != nil {
return nil, err
}
2019-07-24 08:03:29 +00:00
var result Page
err = parser.Unmarshal(data, &result)
return &result, err
2017-09-04 21:09:59 +00:00
}