Skip to content

Commit 8413dcb

Browse files
committed
Code refactoring to add *Async* suffix to all async methods.
1 parent 4bbbc2c commit 8413dcb

5 files changed

Lines changed: 29 additions & 29 deletions

File tree

src/main/ITokenClient.cs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ public interface ITokenClient
99
/// Use this method to revoke access_token and generate a new one, for example, if the user would like to reset all connected sessions, or you have reasons to believe the token was compromised. On success, returns an Account object with new access_token and auth_url fields.
1010
/// </summary>
1111
/// <returns>Returns an Account object with new access_token and auth_url fields.</returns>
12-
Task<Account> RevokeAccessToken();
12+
Task<Account> RevokeAccessTokenAsync();
1313

1414
/// <summary>
1515
/// Use this method to get information about a Telegraph account. Returns an Account object on success.
@@ -19,7 +19,7 @@ public interface ITokenClient
1919
/// This can be specified as a flagged enum, viz: AccountFields.ShortName | AccountFields.AuthorName | AccountFields.PageCount.
2020
/// </param>
2121
/// <returns>Returns an Account object on success.</returns>
22-
Task<Account> GetAccountInformation(AccountFields flaggedFields = AccountFields.ShortName | AccountFields.AuthorName | AccountFields.AuthorUrl);
22+
Task<Account> GetAccountInformationAsync(AccountFields flaggedFields = AccountFields.ShortName | AccountFields.AuthorName | AccountFields.AuthorUrl);
2323

2424
/// <summary>
2525
/// Use this method to get information about a Telegraph account. Returns an Account object on success.
@@ -28,7 +28,7 @@ public interface ITokenClient
2828
/// List of account fields to return. Available fields: short_name, author_name, author_url, auth_url, page_count.
2929
/// </param>
3030
/// <returns>Returns an Account object on success.</returns>
31-
Task<Account> GetAccountInformationByString(string[] fields = null);
31+
Task<Account> GetAccountInformationByStringAsync(string[] fields = null);
3232

3333
/// <summary>
3434
/// Use this method to update information about a Telegraph account. Pass only the parameters that you want to edit. On success, returns an Account object with the default fields.
@@ -37,7 +37,7 @@ public interface ITokenClient
3737
/// <param name="authorName">New default author name used when creating new articles.</param>
3838
/// <param name="authorUrl">New 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 or channel.</param>
3939
/// <returns>An Account object with the default fields.</returns>
40-
Task<Account> EditAccountInformation(string shortName, string authorName, string authorUrl);
40+
Task<Account> EditAccountInformationAsync(string shortName, string authorName, string authorUrl);
4141

4242
/// <summary>
4343
/// Use this method to create a new Telegraph page.
@@ -48,7 +48,7 @@ public interface ITokenClient
4848
/// <param name="authorUrl">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.</param>
4949
/// <param name="returnContent">If true, a content field will be returned in the Page object.</param>
5050
/// <returns> On success, returns a Page object.</returns>
51-
Task<Page> CreatePage(string title, NodeElement[] content, string authorName = null,
51+
Task<Page> CreatePageAsync(string title, NodeElement[] content, string authorName = null,
5252
string authorUrl = null, bool returnContent = false);
5353

5454
/// <summary>
@@ -60,14 +60,14 @@ Task<Page> CreatePage(string title, NodeElement[] content, string authorName = n
6060
/// <param name="authorUrl">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.</param>
6161
/// <param name="returnContent">If true, a content field will be returned in the Page object.</param>
6262
/// <returns>On success, returns a Page object.</returns>
63-
Task<Page> EditPage(string path, string title, NodeElement[] content, string authorName = null, string authorUrl = null, bool returnContent = false);
63+
Task<Page> EditPageAsync(string path, string title, NodeElement[] content, string authorName = null, string authorUrl = null, bool returnContent = false);
6464

6565
/// <summary>
6666
/// Use this method to get a list of pages belonging to a Telegraph account.
6767
/// </summary>
6868
/// <param name="offset">Sequential number of the first page to be returned. (default = 0)</param>
6969
/// <param name="limit">Limits the number of pages to be retrieved. (0 - 200, default = 50)</param>
7070
/// <returns>Returns a PageList object, sorted by most recently created pages first.</returns>
71-
Task<PageList> GetPageList(int offset, int limit);
71+
Task<PageList> GetPageListAsync(int offset, int limit);
7272
}
7373
}

src/main/TelegraphClient.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ await PostAsync<CreateAccountRequest, Account>(
4242
/// <param name="path">Required. Path to the Telegraph page (in the format Title-12-31, i.e. everything that comes after http://telegra.ph/).</param>
4343
/// <param name="returnContent">If true, content field will be returned in Page object.</param>
4444
/// <returns>Returns a Page object on success.</returns>
45-
public async Task<Page> GetPage(string path, bool returnContent = false)
45+
public async Task<Page> GetPageAsync(string path, bool returnContent = false)
4646
{
4747
return (
4848
await PostAsync<GetPageRequest, Page>(
@@ -62,7 +62,7 @@ await PostAsync<GetPageRequest, Page>(
6262
/// <param name="day">Required if hour is passed. If passed, the number of page views for the requested day will be returned.</param>
6363
/// <param name="hour">If passed, the number of page views for the requested hour will be returned.</param>
6464
/// <returns>Returns a PageViews object on success. By default, the total number of page views will be returned.</returns>
65-
public async Task<PageViews> GetViews(string path, int? year = null, int? month = null, int? day = null, int? hour = null)
65+
public async Task<PageViews> GetViewsAsync(string path, int? year = null, int? month = null, int? day = null, int? hour = null)
6666
{
6767
// Do some validations!
6868

src/main/TokenClient.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public TokenClient(string accessToken, TelegraphClient client)
2222
/// Use this method to revoke access_token and generate a new one, for example, if the user would like to reset all connected sessions, or you have reasons to believe the token was compromised. On success, returns an Account object with new access_token and auth_url fields.
2323
/// </summary>
2424
/// <returns>Returns an Account object with new access_token and auth_url fields.</returns>
25-
public async Task<Account> RevokeAccessToken()
25+
public async Task<Account> RevokeAccessTokenAsync()
2626
{
2727
return (await _client.PostAsync<RevokeAccessTokenRequest, Account>(
2828
"revokeAccessToken",
@@ -38,7 +38,7 @@ public async Task<Account> RevokeAccessToken()
3838
/// This can be specified as a flagged enum, viz: AccountFields.ShortName | AccountFields.AuthorName | AccountFields.PageCount.
3939
/// </param>
4040
/// <returns>Returns an Account object on success.</returns>
41-
public async Task<Account> GetAccountInformation(AccountFields flaggedFields = AccountFields.ShortName | AccountFields.AuthorName | AccountFields.AuthorUrl)
41+
public async Task<Account> GetAccountInformationAsync(AccountFields flaggedFields = AccountFields.ShortName | AccountFields.AuthorName | AccountFields.AuthorUrl)
4242
{
4343
Func<AccountFields, AccountFields, bool> isIncluded =
4444
(combinedFields, fieldToTest) => (combinedFields & fieldToTest) == fieldToTest;
@@ -56,7 +56,7 @@ public async Task<Account> GetAccountInformation(AccountFields flaggedFields = A
5656
if (isIncluded(flaggedFields, entry.Key))
5757
fields.Add(entry.Value);
5858

59-
return await GetAccountInformationByString(fields.ToArray());
59+
return await GetAccountInformationByStringAsync(fields.ToArray());
6060
}
6161

6262
/// <summary>
@@ -66,7 +66,7 @@ public async Task<Account> GetAccountInformation(AccountFields flaggedFields = A
6666
/// List of account fields to return. Available fields: short_name, author_name, author_url, auth_url, page_count.
6767
/// </param>
6868
/// <returns>Returns an Account object on success.</returns>
69-
public async Task<Account> GetAccountInformationByString(string[] fields = null) =>
69+
public async Task<Account> GetAccountInformationByStringAsync(string[] fields = null) =>
7070
(await _client.PostAsync<GetAccountInfoRequest, Account>(
7171
"getAccountInfo",
7272
new GetAccountInfoRequest() { AccessToken = _accessToken, Fields = fields }
@@ -79,7 +79,7 @@ public async Task<Account> GetAccountInformationByString(string[] fields = null)
7979
/// <param name="authorName">New default author name used when creating new articles.</param>
8080
/// <param name="authorUrl">New 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 or channel.</param>
8181
/// <returns>An Account object with the default fields.</returns>
82-
public async Task<Account> EditAccountInformation(string shortName, string authorName, string authorUrl) =>
82+
public async Task<Account> EditAccountInformationAsync(string shortName, string authorName, string authorUrl) =>
8383
(await _client.PostAsync<EditAccountInfoRequest, Account>("editAccountInfo", new EditAccountInfoRequest()
8484
{
8585
AccessToken = _accessToken,
@@ -97,7 +97,7 @@ public async Task<Account> EditAccountInformation(string shortName, string autho
9797
/// <param name="authorUrl">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.</param>
9898
/// <param name="returnContent">If true, a content field will be returned in the Page object.</param>
9999
/// <returns> On success, returns a Page object.</returns>
100-
public async Task<Page> CreatePage(string title, NodeElement[] content, string authorName = null,
100+
public async Task<Page> CreatePageAsync(string title, NodeElement[] content, string authorName = null,
101101
string authorUrl = null, bool returnContent = false)
102102
{
103103
return (
@@ -125,7 +125,7 @@ await _client.PostAsync<PageRequest, Page>(
125125
/// <param name="authorUrl">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.</param>
126126
/// <param name="returnContent">If true, a content field will be returned in the Page object.</param>
127127
/// <returns>On success, returns a Page object.</returns>
128-
public async Task<Page> EditPage(string path, string title, NodeElement[] content, string authorName = null, string authorUrl = null, bool returnContent = false)
128+
public async Task<Page> EditPageAsync(string path, string title, NodeElement[] content, string authorName = null, string authorUrl = null, bool returnContent = false)
129129
{
130130
return (
131131
await _client.PostAsync<PageRequest, Page>(
@@ -149,7 +149,7 @@ await _client.PostAsync<PageRequest, Page>(
149149
/// <param name="offset">Sequential number of the first page to be returned. (default = 0)</param>
150150
/// <param name="limit">Limits the number of pages to be retrieved. (0 - 200, default = 50)</param>
151151
/// <returns>Returns a PageList object, sorted by most recently created pages first.</returns>
152-
public async Task<PageList> GetPageList(int offset, int limit)
152+
public async Task<PageList> GetPageListAsync(int offset, int limit)
153153
{
154154
return (
155155
await _client.PostAsync<GetPageListRequest, PageList>(

src/test-console/AccountTests.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ public void ShouldBeAbleToCreateNewAccount()
2525
public void ShouldBeAbleToGetAccountInformation()
2626
{
2727
var tokenClient = _client.GetTokenClient("b968da509bb76866c35425099bc0989a5ec3b32997d55286c657e6994bbb");
28-
var acctInfo = tokenClient.GetAccountInformation(AccountFields.ShortName | AccountFields.PageCount).Result;
28+
var acctInfo = tokenClient.GetAccountInformationAsync(AccountFields.ShortName | AccountFields.PageCount).Result;
2929
Assert.Equal("Sandbox",acctInfo.ShortName);
3030
Assert.True(acctInfo.PageCount > 1211);
3131
Assert.Null(acctInfo.AuthorName);
@@ -40,7 +40,7 @@ public void ShouldBeAbleToRevokeAccessToken()
4040
var tokenClient = _client.GetTokenClient(result.AccessToken);
4141

4242
// Revoke the access token of the new account
43-
var acctInfo = tokenClient.RevokeAccessToken().Result;
43+
var acctInfo = tokenClient.RevokeAccessTokenAsync().Result;
4444

4545
// Check for new access_token and new authorization url
4646
Assert.NotNull(acctInfo.AccessToken);
@@ -57,10 +57,10 @@ public void ShouldBeAbleToEditAccountInformation()
5757

5858
// Update account information
5959
var acctInfo =
60-
tokenClient.EditAccountInformation("Sandbox-Edited", "Anonymous-Edited", "http://google.com").Result;
60+
tokenClient.EditAccountInformationAsync("Sandbox-Edited", "Anonymous-Edited", "http://google.com").Result;
6161

6262
// Get account information
63-
var updateAcctInfo = tokenClient.GetAccountInformation().Result;
63+
var updateAcctInfo = tokenClient.GetAccountInformationAsync().Result;
6464

6565
// Ensure updated and retrieved account information match
6666
Assert.Equal(updateAcctInfo.AuthorName, acctInfo.AuthorName);

src/test-console/PageTests.cs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public PageTests()
2020
[Fact]
2121
public void ShouldBeAbleToCreatePage()
2222
{
23-
var page = _tokenClient.CreatePage(
23+
var page = _tokenClient.CreatePageAsync(
2424
title: "Sample Page",
2525
authorName: "Anonymous",
2626
returnContent: true,
@@ -39,7 +39,7 @@ public void ShouldBeAbleToCreatePage()
3939
[Fact]
4040
public void ShouldBeAbleToGetAPage()
4141
{
42-
var page = _tokenClient.CreatePage(
42+
var page = _tokenClient.CreatePageAsync(
4343
title: "Sample Page",
4444
authorName: "Anonymous",
4545
returnContent: true,
@@ -48,17 +48,17 @@ public void ShouldBeAbleToGetAPage()
4848
}.ToArray()
4949
).Result;
5050

51-
var pageRetrieved = _client.GetPage(page.Path).Result;
51+
var pageRetrieved = _client.GetPageAsync(page.Path).Result;
5252
Assert.Null(pageRetrieved.Content);
5353

54-
pageRetrieved = _client.GetPage(page.Path, true).Result;
54+
pageRetrieved = _client.GetPageAsync(page.Path, true).Result;
5555
Assert.NotNull(pageRetrieved.Content);
5656
}
5757

5858
[Fact]
5959
public void ShouldBeAbleToEditAPage()
6060
{
61-
var page = _tokenClient.CreatePage(
61+
var page = _tokenClient.CreatePageAsync(
6262
title: "Sample Page",
6363
authorName: "Anonymous",
6464
returnContent: true,
@@ -72,7 +72,7 @@ public void ShouldBeAbleToEditAPage()
7272

7373

7474
// Update the page and get the modified copy from the server
75-
var modifiedPage = _tokenClient.EditPage(
75+
var modifiedPage = _tokenClient.EditPageAsync(
7676
page.Path,
7777
page.Title,
7878
page.Content.ToArray(),
@@ -103,14 +103,14 @@ public void ShouldBeAbleToEditAPage()
103103
[Fact]
104104
public void ShouldBeAbleToGetPageViews()
105105
{
106-
var response = _client.GetViews("Sample-Page-12-15", 2016, 12).Result;
106+
var response = _client.GetViewsAsync("Sample-Page-12-15", 2016, 12).Result;
107107
Assert.Equal(40, response.Views);
108108
}
109109

110110
[Fact]
111111
public void ShouldBeAbleToGetPageList()
112112
{
113-
var response = _tokenClient.GetPageList(0, 40).Result;
113+
var response = _tokenClient.GetPageListAsync(0, 40).Result;
114114

115115
// Was 1227 as at when this code was written.
116116
// Should be more than now!

0 commit comments

Comments
 (0)