Skip to content

Commit 224ea58

Browse files
committed
Enhance the Client to retrieve user name asynchronously
1 parent 3a51211 commit 224ea58

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

Git.hub/Client.cs

+15-2
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
using System;
22
using System.Collections.Generic;
33
using System.Linq;
4+
using System.Threading.Tasks;
45
using RestSharp;
56
using RestSharp.Authenticators;
67

@@ -148,7 +149,7 @@ public User getCurrentUser()
148149
return user.Data;
149150
}
150151

151-
public User GetUser(string userName)
152+
public async Task<User> GetUserAsync(string userName)
152153
{
153154
if (string.IsNullOrEmpty(userName))
154155
{
@@ -157,10 +158,22 @@ public User GetUser(string userName)
157158

158159
var request = new RestRequest($"/users/{userName}");
159160

160-
var user = client.Get<User>(request);
161+
var user = await client.ExecuteGetTaskAsync<User>(request);
161162
return user.Data;
162163
}
163164

165+
public User GetUser(string userName)
166+
{
167+
if (string.IsNullOrEmpty(userName))
168+
{
169+
throw new ArgumentException("Empty username", nameof(userName));
170+
}
171+
172+
var request = new RestRequest($"/users/{userName}");
173+
174+
return client.Get<User>(request).Data;
175+
}
176+
164177
/// <summary>
165178
/// Searches through all of Github's repositories, similar to the search on the website itself.
166179
/// </summary>

0 commit comments

Comments
 (0)