From b23e935527c924bdbd6d61519204b0b2da1ed076 Mon Sep 17 00:00:00 2001 From: Brian V Date: Fri, 6 Nov 2015 09:39:57 -0500 Subject: [PATCH 1/2] Added method to return a list of users or a single user. --- TechTalk.JiraRestClient/JiraClient.cs | 37 +++++++++++++++++++++++++-- 1 file changed, 35 insertions(+), 2 deletions(-) diff --git a/TechTalk.JiraRestClient/JiraClient.cs b/TechTalk.JiraRestClient/JiraClient.cs index 42fc27e..773acee 100644 --- a/TechTalk.JiraRestClient/JiraClient.cs +++ b/TechTalk.JiraRestClient/JiraClient.cs @@ -320,8 +320,41 @@ public Issue TransitionIssue(IssueRef issue, Transition transition } } - - public IEnumerable GetWatchers(IssueRef issue) + /// + /// Finds the users specified by the search + /// + /// Text to search on (user name, email addres) + /// + public List FindUsers(string search) + { + try + { + var path = String.Format("user/search?username={0}", search); + var request = CreateRequest(Method.GET, path); + var response = ExecuteRequest(request); + AssertStatus(response, HttpStatusCode.OK); + + var result = deserializer.Deserialize>(response); + return result; + } + catch (Exception ex) + { + Trace.TraceError("FindUsers(issue) error: {0}", ex); + throw new JiraClientException( String.Format("Could find user {0}. {1}",search,ex)); + } + } + + /// + /// Returns the first user specified by the search + /// + /// Text to search on (user name, email addres) + /// + public JiraUser FindUser(string search) + { + return FindUsers(search).FirstOrDefault(); + } + + public IEnumerable GetWatchers(IssueRef issue) { try { From 659d50c5c25704f3a30fe5d75b1d1cb31b26404e Mon Sep 17 00:00:00 2001 From: Brian V Date: Fri, 6 Nov 2015 13:04:05 -0500 Subject: [PATCH 2/2] Removed comments from implementation for sake of consistency. --- TechTalk.JiraRestClient/JiraClient.cs | 12 +----------- 1 file changed, 1 insertion(+), 11 deletions(-) diff --git a/TechTalk.JiraRestClient/JiraClient.cs b/TechTalk.JiraRestClient/JiraClient.cs index 773acee..c902e4d 100644 --- a/TechTalk.JiraRestClient/JiraClient.cs +++ b/TechTalk.JiraRestClient/JiraClient.cs @@ -320,11 +320,6 @@ public Issue TransitionIssue(IssueRef issue, Transition transition } } - /// - /// Finds the users specified by the search - /// - /// Text to search on (user name, email addres) - /// public List FindUsers(string search) { try @@ -343,12 +338,7 @@ public List FindUsers(string search) throw new JiraClientException( String.Format("Could find user {0}. {1}",search,ex)); } } - - /// - /// Returns the first user specified by the search - /// - /// Text to search on (user name, email addres) - /// + public JiraUser FindUser(string search) { return FindUsers(search).FirstOrDefault();