using System;
using System.Net;
using TINK.Model.Device;
using TINK.Repository.Exception;
namespace TINK.Repository.Request
{
/// Creates requests if no user is logged in.
public class RequestBuilder : IRequestBuilder
{
/// Constructs a object for building requests.
///
public RequestBuilder(
string merchantId)
{
MerchantId = !string.IsNullOrEmpty(merchantId)
? merchantId
: throw new ArgumentException("Merchant id must not be null.", nameof(merchantId));
}
/// Holds the id denoting the merchant (TINK app).
public string MerchantId { get; }
/// Holds the session cookie if a user is logged in.
public string SessionCookie => string.Empty;
/// Gets request to log user in.
/// Mailaddress of user to log in.
/// Password to log in.
/// Id specifying user and hardware.
/// Response which holds auth cookie
public string DoAuthorization(
string mailAddress,
string password,
string deviceId)
{
return string.Format(
"request=authorization&merchant_id={0}&user_id={1}&user_pw={2}&hw_id={3}",
MerchantId,
WebUtility.UrlEncode(mailAddress),
WebUtility.UrlEncode(password),
deviceId);
}
/// Logs user out.
public string DoAuthout()
{
throw new CallNotRequiredException();
}
/// Gets bikes available.
/// Request to query list of bikes available.
public string GetBikesAvailable()
{
return GetBikesAvailable(MerchantId);
}
/// Gets bikes available.
/// Request to query list of bikes available.
public static string GetBikesAvailable(string merchantId, string sessionCookie = null)
{
return $"request=bikes_available&system=all&authcookie={sessionCookie ?? string.Empty}{merchantId}";
}
/// Get list of stations from file.
/// Request to query list of station.
public string GetStations()
{
return GetStations(MerchantId);
}
/// Get list of stations from file.
/// Request to query list of station.
public static string GetStations(string merchantId, string sessionCookie = null)
{
return $"request=stations_available&authcookie={sessionCookie ?? string.Empty}{merchantId}";
}
/// Gets a list of bikes reserved/ booked by acctive user from Copri.
/// Request to query list of bikes occupied.
public string GetBikesOccupied() => throw new NotSupportedException();
/// Gets booking request response.
/// Id of the bike to book.
/// Response on booking request.
public string DoReserve(string bikeId) => throw new NotSupportedException();
/// Gets cancel booking request response.
/// Id of the bike to book.
/// Response on cancel booking request.
public string DoCancelReservation(string p_iBikeId) => throw new NotSupportedException();
/// Request to calculate authentication keys.
/// Id of the bike to get keys for.
/// Response on request.
public string CalculateAuthParameters(string bikeId) => throw new NotSupportedException();
public string UpateLockingState(string bikeId, LocationDto geolocation, lock_state state, double batteryPercentage)
=> throw new NotSupportedException();
public string DoBook(string bikeId, Guid guid, double batteryPercentage) => throw new NotSupportedException();
public string DoReturn(string bikeId, LocationDto geolocation, ISmartDevice smartDevice) => throw new NotSupportedException();
/// Gets submit feedback request.
/// Id of the bike to which the feedback is related to.
/// General purpose message or error description.
/// True if bike is broken.
/// Submit feedback request.
public string DoSubmitFeedback(
string bikeId,
string message = null,
bool isBikeBroken = false) => throw new NotSupportedException();
}
}