Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

Commit

Permalink
Merge pull request #10 from Kentico/userexists
Browse files Browse the repository at this point in the history
Fixes #5 - REST methods for user retrieval made optimal
  • Loading branch information
ondrejsevcik authored Oct 31, 2016
2 parents 9b20fc0 + b937e68 commit 5185dee
Show file tree
Hide file tree
Showing 2 changed files with 545 additions and 541 deletions.
60 changes: 29 additions & 31 deletions ADImportService/Rest/RestHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,39 +4,37 @@

namespace Kentico.ADImportService
{
/// <summary>
/// Provides basic operation for manipulation with REST reposnes.
/// </summary>
public class RestHelper
{
/// <summary>
/// Get value of given attribute from REST response.
/// </summary>
/// <param name="response">Complete REST response.</param>
/// <param name="attributeName">Object attribute to retrieve.</param>
public static string GetAttributeFromReponse(string response, string attributeName)
{
IEnumerable<string> results = GetAttributesFromReponse(response, attributeName).ToList();
/// <summary>
/// Provides basic operation for manipulation with REST reposnes.
/// </summary>
public class RestHelper
{
/// <summary>
/// Get value of given attribute from REST response.
/// </summary>
/// <param name="response">Complete REST response.</param>
/// <param name="attributeName">Object attribute to retrieve.</param>
public static string GetAttributeFromReponse(string response, string attributeName)
{
return GetAttributesFromReponse(response, attributeName).FirstOrDefault();
}

return results.FirstOrDefault();
}

/// <summary>
/// Get values of given attribute from REST response.
/// </summary>
/// <param name="response">Complete REST response.</param>
/// <param name="attributeName">Object attribute to retrieve.</param>
public static IEnumerable<string> GetAttributesFromReponse(string response, string attributeName)
{
if (!string.IsNullOrEmpty(response) && !string.IsNullOrEmpty(attributeName))
{
Regex idRegex = new Regex(string.Format(@"\<{0}\>(?<id>[^\<\>]*)\</{0}\>", attributeName), RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);

/// <summary>
/// Get values of given attribute from REST response.
/// </summary>
/// <param name="response">Complete REST response.</param>
/// <param name="attributeName">Object attribute to retrieve.</param>
public static IEnumerable<string> GetAttributesFromReponse(string response, string attributeName)
{
if (!string.IsNullOrEmpty(response) && !string.IsNullOrEmpty(attributeName))
{
Regex idRegex = new Regex(string.Format(@"\<{0}\>(?<id>[^\<\>]*)\</{0}\>", attributeName), RegexOptions.IgnoreCase | RegexOptions.CultureInvariant);
return idRegex.Matches(response).Cast<Match>().Select(m => m.Groups["id"].Value).ToList();
}

return idRegex.Matches(response).Cast<Match>().Select(m => m.Groups["id"].Value).ToList();
}

return new List<string>();
}
}
return new List<string>();
}
}
}
Loading

0 comments on commit 5185dee

Please sign in to comment.