telegraph/create_account.go

34 lines
930 B
Go
Raw Normal View History

2017-09-04 21:09:59 +00:00
package telegraph
import (
json "github.com/pquerna/ffjson/ffjson"
http "github.com/valyala/fasthttp"
)
2018-07-27 11:51:14 +00:00
// CreateAccount create a new Telegraph account. Most users only need one
// account, but this can be useful for channel administrators who would like to
// keep individual author names and profile links for each of their channels. On
// success, returns an Account object with the regular fields and an additional
// access_token field.
func CreateAccount(account *Account) (r *Account, err error) {
if account == nil {
return nil, ErrNoInputData
}
args := http.AcquireArgs()
2018-07-27 11:51:14 +00:00
defer http.ReleaseArgs(args)
2017-09-04 21:09:59 +00:00
args.Add("short_name", account.ShortName) // required
args.Add("author_name", account.AuthorName)
args.Add("author_url", account.AuthorURL)
2018-07-27 11:51:14 +00:00
dst := new(Response)
dst, err = makeRequest("createAccount", args)
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
r = new(Account)
err = json.Unmarshal(*dst.Result, r)
return
2017-09-04 21:09:59 +00:00
}