mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-15 14:46:39 +01:00
83 lines
2.9 KiB
C#
83 lines
2.9 KiB
C#
|
|
using System.Net;
|
|
using TINK.Model.Connector;
|
|
using TINK.Model.Device;
|
|
|
|
namespace TINK.Repository.Request
|
|
{
|
|
public static class RequestBuilderHelper
|
|
{
|
|
/// <summary>
|
|
/// Gets the REST language parameter.
|
|
/// </summary>
|
|
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
|
|
/// <returns></returns>
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary> Gets the smart device parameters. </summary>
|
|
/// <returns>in a format which is url encode invariant.</returns>
|
|
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;
|
|
|
|
/// <summary>
|
|
/// Converts from one locking state enum to another.
|
|
/// </summary>
|
|
/// <param name="state">Locking state to convert.</param>
|
|
/// <returns>Target state.</returns>
|
|
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;
|
|
}
|
|
}
|
|
|
|
/// <summary> Gets the station id filter. </summary>
|
|
/// <returns>Station id filter.</returns>
|
|
public static string GetStationId(this string stationId)
|
|
=> !string.IsNullOrEmpty(stationId)
|
|
? $"&station={WebUtility.UrlEncode(stationId)}"
|
|
: string.Empty;
|
|
|
|
/// <summary> Gets the bike id filter. </summary>
|
|
/// <returns>Bike id filter.</returns>
|
|
public static string GetBikeId(this string bikeId)
|
|
=> !string.IsNullOrEmpty(bikeId)
|
|
? $"&bike={WebUtility.UrlEncode(bikeId)}"
|
|
: string.Empty;
|
|
}
|
|
}
|