This commit is contained in:
2020-04-27 23:28:36 +00:00
parent 0fcc7772f3
commit f4922b8a92
2 changed files with 143 additions and 119 deletions

View File

@@ -17,7 +17,7 @@ namespace AyaNova.PlugIn.V8
const string API_BASE_ROUTE = "api/v8/";
static HttpClient client = new HttpClient();
//url once known to be good
static string ApiBaseUrl { get; set; }
internal static string ApiBaseUrl { get; set; }
internal static string JWT { get; set; }
static bool Initialized { get; set; }
@@ -183,6 +183,38 @@ namespace AyaNova.PlugIn.V8
}
#endregion
#region Misc utils
public static string NormalizeTag(string inObj)
{
//Must be lowercase per rules
//This may be naive when we get international customers but for now supporting utf-8 and it appears it's safe to do this with unicode
inObj = inObj.ToLowerInvariant();
//No spaces in tags, replace with dashes
inObj = inObj.Replace(" ", "-");
//Remove multiple dash sequences
inObj = System.Text.RegularExpressions.Regex.Replace(inObj, "-+", "-");
//Ensure doesn't start or end with a dash
inObj = inObj.Trim('-');
//No longer than 255 characters
inObj = MaxLength(inObj, 255);
return inObj;
}
/// <summary>
/// Trim a string if necessary
/// </summary>
/// <param name="s"></param>
/// <param name="maxLength"></param>
/// <returns></returns>
public static string MaxLength(string s, int maxLength)
{
if (s.Length > maxLength)
s = s.Substring(0, maxLength);
return s;
}
#endregion
}//eoc