Make Account fields as constants

It helps to avoid typos in the listing of GetAccountInfo arguments
This commit is contained in:
Maxim Lebedev 2017-12-13 15:11:23 +05:00
parent a979bbbb5d
commit 95664dde08
No known key found for this signature in database
GPG Key ID: F8978F46FF0FFA4F
3 changed files with 22 additions and 4 deletions

View File

@ -8,8 +8,26 @@ import (
http "github.com/valyala/fasthttp"
)
// GetAccountInfo get information about a Telegraph account. Returns an
// Account object on success.
const (
// FieldShortName used as GetAccountInfo argument for getting account name.
FieldShortName = "short_name"
// FieldAuthorName used as GetAccountInfo argument for getting author name.
FieldAuthorName = "author_name"
// FieldAuthorURL used as GetAccountInfo argument for getting profile link.
FieldAuthorURL = "author_url"
// FieldAuthURL used as GetAccountInfo argument for getting URL to authorize a browser on
// telegra.ph.
FieldAuthURL = "auth_url"
// FieldPageCount used as GetAccountInfo argument for getting number of pages belonging to the
// Telegraph account.
FieldPageCount = "page_count"
)
// GetAccountInfo get information about a Telegraph account. Returns an Account object on success.
func (account *Account) GetAccountInfo(fields ...string) (*Account, error) {
args := http.AcquireArgs()

View File

@ -54,7 +54,7 @@ func testInvalidEditPage(t *testing.T) {
}
func testInvalidGetAccountInfo(t *testing.T) {
if _, err := invalidAccount.GetAccountInfo("short_name", "page_count"); err == nil {
if _, err := invalidAccount.GetAccountInfo(FieldShortName, FieldPageCount); err == nil {
t.Error()
}
}

View File

@ -113,7 +113,7 @@ func testValidEditPage(t *testing.T) {
}
func testValidGetAccountInfo(t *testing.T) {
info, err := validAccount.GetAccountInfo("short_name", "page_count")
info, err := validAccount.GetAccountInfo(FieldShortName, FieldPageCount)
if err != nil {
t.Error(err.Error())
t.FailNow()