-
Notifications
You must be signed in to change notification settings - Fork 1
/
edit_page.go
52 lines (41 loc) · 1.33 KB
/
edit_page.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
package telegraph
import (
"path"
)
type editPage struct {
// Access token of the Telegraph account.
AccessToken string `json:"access_token"`
// Path to the page.
Path string `json:"path"`
// Page title.
Title string `json:"title"`
// Content of the page.
Content []Node `json:"content"`
// Author name, displayed below the article's title.
AuthorName string `json:"author_name,omitempty"`
// 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.
AuthorURL string `json:"author_url,omitempty"`
// If true, a content field will be returned in the Page object.
ReturnContent bool `json:"return_content,omitempty"`
}
// EditPage edit an existing Telegraph page. On success, returns a Page object.
func (c *client) EditPage(update Page, returnContent bool) (*Page, error) {
data, err := c.makeRequest(path.Join("editPage", update.Path), editPage{
AccessToken: c.Account().AccessToken,
Path: update.Path,
Title: update.Title,
Content: update.Content,
AuthorName: update.AuthorName,
AuthorURL: update.AuthorURL,
ReturnContent: returnContent,
})
if err != nil {
return nil, err
}
result := new(Page)
if err = parser.Unmarshal(data, result); err != nil {
return nil, err
}
return result, nil
}