using System.Net; using TINK.Model.Connector; using TINK.Model.Device; namespace TINK.Repository.Request { public static class RequestBuilderHelper { /// /// Gets the REST language parameter. /// /// Two letter ISO language name. /// public static string GetLanguageParameter(string uiIsoLangugageName) => !string.IsNullOrEmpty(uiIsoLangugageName) ? $"&lang={uiIsoLangugageName}" : string.Empty; public static lock_state? GetLockState(this LockingAction? action) { switch (action) { case LockingAction.Open: return lock_state.unlocking; case LockingAction.Close: return lock_state.locking; default: return null; } } /// Gets the smart device parameters. /// in a format which is urlencode invariant. public static string GetSmartDeviceParameters(this ISmartDevice smartDevice) => smartDevice != null ? $"{(!string.IsNullOrEmpty(smartDevice.Manufacturer) ? $"&user_device_manufacturer={WebUtility.UrlEncode(smartDevice.Manufacturer)}" : string.Empty)}" + $"{(!string.IsNullOrEmpty(smartDevice.Model) ? $"&user_device_model={WebUtility.UrlEncode(smartDevice.Model)}" : string.Empty)}" + $"{(!string.IsNullOrEmpty(smartDevice.Platform.ToString()) ? $"&user_device_platform={WebUtility.UrlEncode(smartDevice.Platform.ToString())}" : string.Empty)}" + $"{(!string.IsNullOrEmpty(smartDevice.VersionText) ? $"&user_device_version={WebUtility.UrlEncode(smartDevice.VersionText)}" : string.Empty)}" + $"{(!string.IsNullOrEmpty(smartDevice.Identifier) ? $"&user_device_id={WebUtility.UrlEncode(smartDevice.Identifier)}" : string.Empty)}" : string.Empty; } }