From 95664dde08b11c91401f0fa04b82f3884b68b4f5 Mon Sep 17 00:00:00 2001 From: Maxim Lebedev Date: Wed, 13 Dec 2017 15:11:23 +0500 Subject: [PATCH] :wheelchair: Make Account fields as constants It helps to avoid typos in the listing of GetAccountInfo arguments --- get_account_info.go | 22 ++++++++++++++++++++-- invalid_test.go | 2 +- valid_test.go | 2 +- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/get_account_info.go b/get_account_info.go index 58c3639..9a060ce 100644 --- a/get_account_info.go +++ b/get_account_info.go @@ -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() diff --git a/invalid_test.go b/invalid_test.go index 25b4f07..da577eb 100644 --- a/invalid_test.go +++ b/invalid_test.go @@ -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() } } diff --git a/valid_test.go b/valid_test.go index 1a66ee6..16c0aa7 100644 --- a/valid_test.go +++ b/valid_test.go @@ -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()