👽 (Maybe) last library API changes

This commit is contained in:
Maxim Lebedev 2017-07-01 17:16:17 +05:00
parent f3eedf50d4
commit 2d2e1d9205
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
3 changed files with 12 additions and 6 deletions

View File

@ -13,21 +13,21 @@ import (
// to keep individual author names and profile links for each of their // to keep individual author names and profile links for each of their
// channels. On success, returns an Account object with the regular fields and // channels. On success, returns an Account object with the regular fields and
// an additional access_token field. // an additional access_token field.
func CreateAccount(shortName, authorName, authorURL string) (*Account, error) { func CreateAccount(account *Account) (*Account, error) {
var args http.Args var args http.Args
// Account name, helps users with several accounts remember which they are // Account name, helps users with several accounts remember which they are
// currently using. Displayed to the user above the "Edit/Publish" button // currently using. Displayed to the user above the "Edit/Publish" button
// on Telegra.ph, other users don't see this name. // on Telegra.ph, other users don't see this name.
args.Add("short_name", shortName) // required args.Add("short_name", account.ShortName) // required
// Default author name used when creating new articles. // Default author name used when creating new articles.
args.Add("author_name", authorName) args.Add("author_name", account.AuthorName)
// Default profile link, opened when users click on the author's name // Default profile link, opened when users click on the author's name
// below the title. Can be any link, not necessarily to a Telegram profile // below the title. Can be any link, not necessarily to a Telegram profile
// or channel. // or channel.
args.Add("author_url", authorURL) args.Add("author_url", account.AuthorURL)
url := fmt.Sprintf(APIEndpoint, "createAccount") url := fmt.Sprintf(APIEndpoint, "createAccount")
body, err := request(url, &args) body, err := request(url, &args)

View File

@ -11,7 +11,8 @@ func TestContentFormatByWTF(t *testing.T) {
} }
func TestCreateInvalidAccount(t *testing.T) { func TestCreateInvalidAccount(t *testing.T) {
_, err := CreateAccount("", "", "") var account Account
_, err := CreateAccount(&account)
if err == nil { if err == nil {
t.Error() t.Error()
} }

View File

@ -23,7 +23,12 @@ func TestContentFormatByBytes(t *testing.T) {
} }
func TestCreateValidAccount(t *testing.T) { func TestCreateValidAccount(t *testing.T) {
account, err := CreateAccount("Sandbox", "Anonymous", "") newAccount := &Account{
ShortName: "Sandbox",
AuthorName: "Anonymous",
}
account, err := CreateAccount(newAccount)
if err != nil { if err != nil {
t.Error(err) t.Error(err)
} }