sharee.bike-App/TINKLib/Repository/Request/RequestBuilderHelper.cs

70 lines
2.4 KiB
C#
Raw Normal View History

2022-12-27 21:08:09 +01:00
2023-02-22 14:03:35 +01:00
using System.Net;
2022-12-27 21:08:09 +01:00
using TINK.Model.Connector;
2023-02-22 14:03:35 +01:00
using TINK.Model.Device;
2022-12-27 21:08:09 +01:00
2022-08-30 15:42:25 +02:00
namespace TINK.Repository.Request
{
2022-09-06 16:08:19 +02:00
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;
2022-12-27 21:08:09 +01:00
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;
}
}
2023-02-22 14:03:35 +01:00
/// <summary> Gets the smart device parameters. </summary>
2023-08-31 12:20:06 +02:00
/// <returns>in a format which is url encode invariant.</returns>
2023-02-22 14:03:35 +01:00
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;
2023-08-31 12:20:06 +02:00
/// <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;
}
}
2022-09-06 16:08:19 +02:00
}
2022-08-30 15:42:25 +02:00
}