Skip to content

Commit 1585670

Browse files
committed
added Client.getCurrentUser()
1 parent 097a35c commit 1585670

File tree

2 files changed

+19
-0
lines changed

2 files changed

+19
-0
lines changed

Git.hub.Demo/Program.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ static void Main(string[] args)
1212
{
1313
Client client = new Client();
1414

15+
client.setCredentials("mabako", "");
16+
Console.WriteLine("Logged in as: {0}", client.getCurrentUser());
17+
18+
Console.WriteLine();
1519
Console.WriteLine("Repositories of mabako?");
1620
client.getRepositories("mabako").ToList().ForEach(repo => Console.WriteLine(" {0}", repo.Name));
1721

Git.hub/Client.cs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,5 +110,20 @@ public IList<Repository> getOrganizationRepositories(string organization)
110110
list.ForEach(r => { r._client = client; r.Organization = org; });
111111
return list;
112112
}
113+
114+
/// <summary>
115+
/// Retrieves the current user.
116+
///
117+
/// Requires to be logged in (OAuth/User+Password).
118+
/// </summary>
119+
/// <returns>current user</returns>
120+
public User getCurrentUser()
121+
{
122+
if (client.Authenticator == null)
123+
throw new ArgumentException("no authentication details");
124+
125+
var request = new RestRequest("/user");
126+
return client.Get<User>(request).Data;
127+
}
113128
}
114129
}

0 commit comments

Comments
 (0)