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 url encode 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; /// /// Converts from one locking state enum to another. /// /// Locking state to convert. /// Target state. public static lock_state? GetLockState(this Model.Bikes.BikeInfoNS.BluetoothLock.LockingState state) { switch (state) { case Model.Bikes.BikeInfoNS.BluetoothLock.LockingState.Open: return lock_state.unlocked; case Model.Bikes.BikeInfoNS.BluetoothLock.LockingState.Closed: return lock_state.locked; case Model.Bikes.BikeInfoNS.BluetoothLock.LockingState.UnknownFromHardwareError: return lock_state.unspecific; default: return null; } } /// Gets the station id filter. /// Station id filter. public static string GetStationId(this string stationId) => !string.IsNullOrEmpty(stationId) ? $"&station={WebUtility.UrlEncode(stationId)}" : string.Empty; /// Gets the bike id filter. /// Bike id filter. public static string GetBikeId(this string bikeId) => !string.IsNullOrEmpty(bikeId) ? $"&bike={WebUtility.UrlEncode(bikeId)}" : string.Empty; } }