sharee.bike-App/SharedBusinessLogic/Repository/Request/RequestBuilder.cs

166 lines
7.1 KiB
C#
Raw Normal View History

2022-09-20 13:51:55 +02:00
using System;
2021-08-01 17:24:15 +02:00
using System.Collections.Generic;
2021-05-13 20:03:07 +02:00
using System.Net;
2024-04-09 12:53:23 +02:00
using ShareeBike.Model.Bikes.BikeInfoNS.BluetoothLock;
using ShareeBike.Model.Connector;
using ShareeBike.Model.Device;
using ShareeBike.Repository.Exception;
2021-05-13 20:03:07 +02:00
2024-04-09 12:53:23 +02:00
namespace ShareeBike.Repository.Request
2021-05-13 20:03:07 +02:00
{
2022-09-06 16:08:19 +02:00
/// <summary> Creates requests if no user is logged in.</summary>
public class RequestBuilder : IRequestBuilder
{
/// <summary> Constructs a object for building requests. </summary>
2023-01-18 14:22:51 +01:00
/// <param name="merchantId">Holds the id denoting the merchant.</param>
2022-09-06 16:08:19 +02:00
/// <param name="uiIsoLangugageName">Two letter ISO language name.</param>
2023-02-22 14:03:35 +01:00
/// <param name="smartDevice">Holds info about smart device.</param>
2022-09-06 16:08:19 +02:00
public RequestBuilder(
string merchantId,
2023-02-22 14:03:35 +01:00
string uiIsoLangugageName,
ISmartDevice smartDevice = null)
2022-09-06 16:08:19 +02:00
{
MerchantId = !string.IsNullOrEmpty(merchantId)
? merchantId
: throw new ArgumentException("Merchant id must not be null.", nameof(merchantId));
2023-01-18 14:22:51 +01:00
UiIsoLanguageNameParameter = RequestBuilderHelper.GetLanguageParameter(WebUtility.UrlEncode(uiIsoLangugageName));
2022-09-06 16:08:19 +02:00
2023-01-18 14:22:51 +01:00
AuthCookieParameter = $"&authcookie={WebUtility.UrlEncode(MerchantId)}";
2023-02-22 14:03:35 +01:00
SmartDevice = smartDevice;
2022-09-06 16:08:19 +02:00
}
2023-01-18 14:22:51 +01:00
/// <summary>Holds the id denoting the merchant.</summary>
2022-09-06 16:08:19 +02:00
public string MerchantId { get; }
/// <summary> Holds the session cookie if a user is logged in. </summary>
public string SessionCookie => string.Empty;
/// <summary> Holds the current ui two letter ISO language name. </summary>
private string UiIsoLanguageNameParameter { get; }
/// <summary> Auth cookie parameter. </summary>
private string AuthCookieParameter { get; }
2023-02-22 14:03:35 +01:00
/// <summary>Holds info about smart device.</summary>
private ISmartDevice SmartDevice { get; }
2022-09-06 16:08:19 +02:00
/// <summary> Gets request to log user in. </summary>
/// <param name="mailAddress">Mailaddress of user to log in.</param>
/// <param name="password">Password to log in.</param>
/// <param name="deviceId">Id specifying user and hardware.</param>
/// <remarks>Response which holds auth cookie <see cref="ResponseBase.authcookie"/></remarks>
public string DoAuthorization(
string mailAddress,
string password,
string deviceId)
=> "request=authorization" +
$"&merchant_id={MerchantId}" +
$"&user_id={WebUtility.UrlEncode(mailAddress)}" +
$"&user_pw={WebUtility.UrlEncode(password)}" +
2023-01-18 14:22:51 +01:00
$"&hw_id={WebUtility.UrlEncode(deviceId)}" +
2022-09-06 16:08:19 +02:00
UiIsoLanguageNameParameter;
/// <summary> Logs user out. </summary>
public string DoAuthout()
=> throw new CallNotRequiredException();
/// <summary>Gets bikes available.</summary>
2023-11-21 15:26:57 +01:00
/// <param name="stationId"> Id of station which is used for filtering bikes. Null if no filtering should be applied.</param>
/// <param name="bikeId"> Id of bike to get.</param>
2022-09-06 16:08:19 +02:00
/// <returns>Request to query list of bikes available.</returns>
2023-11-21 15:26:57 +01:00
public string GetBikesAvailable(string stationId = null, string bikeId = null)
2022-09-06 16:08:19 +02:00
=> "request=bikes_available&system=all" +
2023-11-21 15:26:57 +01:00
stationId.GetStationId() +
bikeId.GetBikeId() +
2022-09-06 16:08:19 +02:00
AuthCookieParameter +
UiIsoLanguageNameParameter;
/// <summary> Get list of stations from file. </summary>
/// <returns>Request to query list of station.</returns>
public string GetStations()
=> "request=stations_available" +
AuthCookieParameter +
2023-02-22 14:03:35 +01:00
SmartDevice.GetSmartDeviceParameters() +
2022-09-06 16:08:19 +02:00
UiIsoLanguageNameParameter;
2023-04-19 12:14:14 +02:00
/// <summary> Gets a list of bikes reserved/ booked by active user from Copri.</summary>
2022-09-06 16:08:19 +02:00
/// <returns>Request to query list of bikes occupied.</returns>
public string GetBikesOccupied()
=> throw new NotSupportedException();
/// <summary> Gets booking request response. </summary>
/// <param name="bikeId">Id of the bike to book.</param>
/// <returns>Response on booking request.</returns>
public string DoReserve(string bikeId)
=> throw new NotSupportedException();
/// <summary> Gets cancel booking request response. </summary>
/// <param name="p_iBikeId">Id of the bike to book.</param>
/// <returns>Response on cancel booking request.</returns>
public string DoCancelReservation(string p_iBikeId)
=> throw new NotSupportedException();
/// <summary> Request to calculate authentication keys. </summary>
/// <param name="bikeId">Id of the bike to get keys for.</param>
/// <returns>Response on request.</returns>
public string CalculateAuthParameters(string bikeId)
=> throw new NotSupportedException();
/// <summary> Gets the request for notifying about start of returning sequence. </summary>
/// <remarks> Operator specific call.</remarks>
/// <param name="bikeId">Id of the bike to return.</param>
/// <returns>Request to notify about start of returning sequence.</returns>
public string StartReturningBike(string bikeId)
=> throw new NotSupportedException();
2022-09-20 13:51:55 +02:00
/// <summary>
/// Not supported if user is not logged in. Lock state is only updated after open/ close which is only possible if user is logged in.
/// </summary>
/// <exception cref="NotSupportedException"></exception>
2023-07-04 11:06:38 +02:00
public string UpdateLockingState(string bikeId, lock_state state, LocationDto geolocation, double batteryPercentage, IVersionInfo versionInfo)
2022-09-06 16:08:19 +02:00
=> throw new NotSupportedException();
2022-12-27 21:08:09 +01:00
public string DoBook(string bikeId, Guid guid, double batteryPercentage, LockingAction? nextAction = null)
2022-09-06 16:08:19 +02:00
=> throw new NotSupportedException();
/// <summary> Gets the request to book and start opening the bike (synonym: booking == renting == mieten). </summary>
/// <param name="bikeId">Id of the bike to book.</param>
/// <returns>Request to booking bike.</returns>
public string BookAvailableAndStartOpening(string bikeId)
=> throw new NotSupportedException();
/// <summary> Gets the request to book and start opening the bike (synonym: booking == renting == mieten). </summary>
/// <param name="bikeId">Id of the bike to book.</param>
/// <returns>Request to booking bike.</returns>
public string BookReservedAndStartOpening(string bikeId)
=> throw new NotSupportedException();
2023-02-22 14:03:35 +01:00
public string DoReturn(string bikeId, LocationDto geolocation)
2022-09-06 16:08:19 +02:00
=> throw new NotSupportedException();
/// <summary> Returns a bike and starts closing. </summary>
/// <param name="bikeId">Id of the bike to return.</param>
/// <param name="smartDevice">Provides info about hard and software.</param>
2023-05-09 08:47:52 +02:00
/// <returns>Response to send to copri.</returns>
2023-02-22 14:03:35 +01:00
public string ReturnAndStartClosing(string bikeId)
2022-09-06 16:08:19 +02:00
=> throw new NotSupportedException();
/// <summary> Gets submit feedback request. </summary>
/// <param name="bikeId">Id of the bike to which the feedback is related to.</param>
/// <param name="message">General purpose message or error description.</param>
/// <param name="isBikeBroken">True if bike is broken.</param>
/// <returns>Submit feedback request.</returns>
public string DoSubmitFeedback(string bikeId, int? currentChargeBars, string message = null, bool isBikeBroken = false)
=> throw new NotSupportedException();
/// <summary>
2023-05-09 08:47:52 +02:00
/// Gets request for submitting mini survey to copri server.
2022-09-06 16:08:19 +02:00
/// </summary>
/// <param name="answers">Collection of answers.</param>
public string DoSubmitMiniSurvey(IDictionary<string, string> answers) =>
throw new NotSupportedException();
}
2021-05-13 20:03:07 +02:00
}