mirror of
https://dev.azure.com/TeilRad/sharee.bike%20App/_git/Code
synced 2024-11-05 10:36:30 +01:00
69 lines
2.4 KiB
C#
69 lines
2.4 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;
|
|
}
|
|
}
|
|
}
|
|
}
|