telegraph/edit_page.go

43 lines
1.0 KiB
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"
json "github.com/pquerna/ffjson/ffjson"
http "github.com/valyala/fasthttp"
)
// EditPage edit an existing Telegraph page. On success, returns a Page object.
2018-07-27 11:51:14 +00:00
func (a *Account) EditPage(update *Page, returnContent bool) (r *Page, err error) {
if update == nil {
return nil, ErrNoInputData
2017-09-04 21:09:59 +00:00
}
2018-07-27 11:51:14 +00:00
var src []byte
src, err = json.Marshal(update.Content)
2017-09-04 21:09:59 +00:00
if err != nil {
2018-07-27 11:51:14 +00:00
return
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
args.Add("content", string(src)) // required
args.Add("author_name", a.AuthorName)
args.Add("author_url", a.AuthorURL)
args.Add("return_content", strconv.FormatBool(returnContent))
2017-09-04 21:09:59 +00:00
2018-07-27 11:51:14 +00:00
dst := new(Response)
dst, err = makeRequest(path.Join("editPage", update.Path), args)
2017-09-04 21:09:59 +00:00
if err != nil {
return nil, err
}
2018-07-27 11:51:14 +00:00
r = new(Page)
err = json.Unmarshal(*dst.Result, r)
return
2017-09-04 21:09:59 +00:00
}