Mini survey added.

Minor fiexes.
This commit is contained in:
Oliver Hauff 2021-08-01 17:24:15 +02:00
parent ddfea49ea6
commit e321764119
73 changed files with 1628 additions and 185 deletions

View file

@ -10,6 +10,7 @@ using TINK.Repository.Request;
using TINK.Repository.Response;
using TINK.Model.Logging;
using TINK.Model.Device;
using System.Collections.Generic;
namespace TINK.Repository
{
@ -231,6 +232,14 @@ namespace TINK.Repository
requestBuilder.DoSubmitFeedback(bikeId, message, isBikeBroken),
UserAgent);
/// <summary> Submits mini survey to copri server. </summary>
/// <param name="answers">Collection of answers.</param>
public Task<ResponseBase> DoSubmitMiniSurvey(IDictionary<string, string> answers)
=> DoSubmitMiniSurvey(
m_oCopriHost.AbsoluteUri,
requestBuilder.DoSubmitMiniSurvey(answers),
UserAgent);
/// <summary> Logs user in. </summary>
/// <param name="copriHost">Host to connect to. </param>
/// <param name="command">Command to log user in.</param>
@ -612,10 +621,10 @@ namespace TINK.Repository
string userAgent = null)
{
#if !WINDOWS_UWP
string l_oBikesAvaialbeResponse;
string cancelOrReturnResponse;
try
{
l_oBikesAvaialbeResponse = await PostAsync(copriHost, command, userAgent);
cancelOrReturnResponse = await PostAsync(copriHost, command, userAgent);
}
catch (System.Exception l_oException)
{
@ -633,7 +642,7 @@ namespace TINK.Repository
}
// Extract bikes from response.
return JsonConvertRethrow.DeserializeObject<ResponseContainer<ReservationCancelReturnResponse>>(l_oBikesAvaialbeResponse)?.shareejson;
return JsonConvertRethrow.DeserializeObject<ResponseContainer<ReservationCancelReturnResponse>>(cancelOrReturnResponse)?.shareejson;
#else
return null;
#endif
@ -672,6 +681,40 @@ namespace TINK.Repository
#endif
}
/// <summary> Submits mini survey to copri server. </summary>
public async Task<ResponseBase> DoSubmitMiniSurvey(
string copriHost,
string command,
string userAgent = null)
{
#if !WINDOWS_UWP
string miniSurveyResponse;
try
{
miniSurveyResponse = await PostAsync(copriHost, command, userAgent);
}
catch (System.Exception l_oException)
{
if (l_oException.GetIsConnectFailureException())
{
throw new WebConnectFailureException("Senden der Miniumfrage aufgrund eines Netzwerkfehlers fehlgeschlagen.", l_oException);
}
if (l_oException.GetIsForbiddenException())
{
throw new WebForbiddenException("Senden der der Miniumfrage aufgrund eines Netzwerkfehlers fehlgeschlagen.", l_oException);
}
throw;
}
// Extract bikes from response.
return JsonConvertRethrow.DeserializeObject<ResponseContainer<ResponseBase>>(miniSurveyResponse)?.shareejson;
#else
return null;
#endif
}
/// <summary> http get- request.</summary>
/// <param name="Url">Ulr to get info from.</param>
/// <returns>response from server</returns>

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using TINK.Model;
using TINK.Model.Device;
@ -1633,7 +1634,13 @@ namespace TINK.Repository
return null;
}
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, string message, bool isBikeBroken, Uri operatorUri) => null;
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, string message, bool isBikeBroken, Uri operatorUri)
=> null;
/// <summary> Submits mini survey to copri server. </summary>
/// <param name="answers">Collection of answers.</param>
public Task<ResponseBase> DoSubmitMiniSurvey(IDictionary<string, string> answers)
=> null ;
/// <summary>
/// Gets a list of bikes reserved/ booked by acctive user from Copri.

View file

@ -5,6 +5,7 @@ using TINK.Repository.Request;
using TINK.Repository.Response;
using TINK.Model.Services.CopriApi;
using TINK.Model.Device;
using System.Collections.Generic;
namespace TINK.Repository
{
@ -183,6 +184,11 @@ namespace TINK.Repository
public Task<SubmitFeedbackResponse> DoSubmitFeedback(string bikeId, string message, bool isBikeBroken, Uri operatorUri) =>
throw new System.Exception("Übermittlung von Feedback im Offlinemodus nicht möglich!");
/// <summary> Submits mini survey to copri server. </summary>
/// <param name="answers">Collection of answers.</param>
public Task<ResponseBase> DoSubmitMiniSurvey(IDictionary<string, string> answers)
=> throw new System.Exception("Übermittlung von der Miniumfrage im Offlinemodus nicht möglich!");
public Task<AuthorizationResponse> DoAuthorizationAsync(string p_strMailAddress, string p_strPassword, string p_strDeviceId)
{
throw new System.Exception("Anmelden im Offlinemodus nicht möglich!");

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using TINK.Model.Device;
using TINK.Repository.Request;
@ -97,6 +98,10 @@ namespace TINK.Repository
bool isBikeBroken,
Uri operatorUri);
/// <summary> Submits mini survey to copri server. </summary>
/// <param name="answers">Collection of answers.</param>
Task<ResponseBase> DoSubmitMiniSurvey(IDictionary<string, string> answers);
/// <summary> True if connector has access to copri server, false if cached values are used. </summary>
bool IsConnected { get; }

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using TINK.Model.Device;
namespace TINK.Repository.Request
@ -85,6 +86,12 @@ namespace TINK.Repository.Request
/// <param name="message">General purpose message or error description.</param>
/// <param name="isBikeBroken">True if bike is broken.</param>
string DoSubmitFeedback(string bikeId, string message = null, bool isBikeBroken = false);
/// <summary>
/// Gets request for submiting mini survey to copri server.
/// </summary>
/// <param name="answers">Collection of answers.</param>
string DoSubmitMiniSurvey(IDictionary<string, string> answers);
}
/// <summary> Copri locking states</summary>

View file

@ -1,4 +1,5 @@
using System;
using System.Collections.Generic;
using System.Net;
using TINK.Model.Device;
using TINK.Repository.Exception;
@ -111,5 +112,12 @@ namespace TINK.Repository.Request
string bikeId,
string message = null,
bool isBikeBroken = false) => throw new NotSupportedException();
/// <summary>
/// Gets request for submiting mini survey to copri server.
/// </summary>
/// <param name="answers">Collection of answers.</param>
public string DoSubmitMiniSurvey(IDictionary<string, string> answers) =>
throw new NotSupportedException();
}
}

View file

@ -1,5 +1,7 @@
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Net;
using TINK.Model.Device;
using TINK.Repository.Exception;
@ -76,21 +78,21 @@ namespace TINK.Repository.Request
/// <remarks> Operator specific call.</remarks>
/// <param name="bikeId">Id of the bike to reserve.</param>
/// <returns>Requst to reserve bike.</returns>
public string DoReserve(string bikeId)
public string DoReserve(string bikeId)
=> $"request=booking_request&bike={bikeId}&authcookie={SessionCookie}{MerchantId}";
/// <summary> Gets request to cancel reservation. </summary>
/// <remarks> Operator specific call.</remarks>
/// <param name="bikeId">Id of the bike to cancel reservation for.</param>
/// <returns>Requst on cancel booking request.</returns>
public string DoCancelReservation(string p_iBikeId)
public string DoCancelReservation(string p_iBikeId)
=> $"request=booking_cancel&bike={p_iBikeId}&authcookie={SessionCookie}{MerchantId}";
/// <summary> Request to get keys. </summary>
/// <remarks> Operator specific call.</remarks>
/// <param name="bikeId">Id of the bike to get keys for.</param>
/// <returns>Request to get keys.</returns>
public string CalculateAuthParameters(string bikeId)
public string CalculateAuthParameters(string bikeId)
=> $"request=booking_update&bike={bikeId}&authcookie={SessionCookie}{MerchantId}&genkey=1";
/// <summary> Gets the request for updating lock state for a booked bike. </summary>
@ -99,7 +101,7 @@ namespace TINK.Repository.Request
/// <param name="state">New locking state.</param>
/// <returns>Request to update locking state.</returns>
public string UpateLockingState(string bikeId, LocationDto geolocation, lock_state state, double batteryPercentage)
{
{
return $"request=booking_update&bike={bikeId}{GetLocationParameters(geolocation)}&lock_state={state}{GetBatteryPercentageParameters(batteryPercentage)}&authcookie={SessionCookie}{MerchantId}";
}
@ -109,7 +111,7 @@ namespace TINK.Repository.Request
/// <param name="guid">Used to publish GUID from app to copri. Used for initial setup of bike in copri.</param>
/// <param name="batteryPercentage">Holds the filling level percentage of the battery.</param>
/// <returns>Request to booking bike.</returns>
public string DoBook(string bikeId, Guid guid, double batteryPercentage)
public string DoBook(string bikeId, Guid guid, double batteryPercentage)
=> $"request=booking_update&bike={bikeId}&authcookie={SessionCookie}{MerchantId}&Ilockit_GUID={guid}&state=occupied&lock_state=unlocked{GetBatteryPercentageParameters(batteryPercentage)}";
/// <summary> Gets request for returning the bike. </summary>
@ -118,7 +120,7 @@ namespace TINK.Repository.Request
/// <param name="geolocation">Geolocation of lock when returning bike.</param>
/// <returns>Requst on returning request.</returns>
public string DoReturn(string bikeId, LocationDto geolocation, ISmartDevice smartDevice)
{
{
return $"request=booking_update" +
$"&bike={bikeId}" +
$"&authcookie={SessionCookie}{MerchantId}" +
@ -133,10 +135,10 @@ namespace TINK.Repository.Request
/// <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(
public string DoSubmitFeedback(
string bikeId,
string message = null,
bool isBikeBroken = false)
string message = null,
bool isBikeBroken = false)
{
if (string.IsNullOrEmpty(message) && !isBikeBroken)
{
@ -161,7 +163,7 @@ namespace TINK.Repository.Request
return $"request=user_feedback&bike={bikeId}&bike_broken=1&message={WebUtility.UrlEncode(message)}&authcookie={SessionCookie}{MerchantId}";
}
private string GetBatteryPercentageParameters(double batteryPercentage) => !double.IsNaN(batteryPercentage)
private string GetBatteryPercentageParameters(double batteryPercentage) => !double.IsNaN(batteryPercentage)
? $"&voltage={batteryPercentage.ToString(CultureInfo.InvariantCulture)}"
: string.Empty;
@ -169,7 +171,7 @@ namespace TINK.Repository.Request
/// <param name="geolocation">Geolocation or null.</param>
private string GetLocationParameters(LocationDto geolocation)
{
if (geolocation == null)
if (geolocation == null)
return string.Empty;
if (geolocation.Accuracy == null)
@ -188,5 +190,21 @@ namespace TINK.Repository.Request
$"{(!string.IsNullOrEmpty(smartDevice.VersionText) ? $"&user_device_version={smartDevice.VersionText}" : string.Empty)}" +
$"{(!string.IsNullOrEmpty(smartDevice.Identifier) ? $"&user_device_id={smartDevice.Identifier}" : string.Empty)}"
: string.Empty;
/// <summary>
/// Gets request for submiting mini survey to copri server.
/// </summary>
/// <param name="answers">Collection of answers.</param>
public string DoSubmitMiniSurvey(IDictionary<string, string> answers)
{
// Remove entires which invalid keys or values.
var validAnsers = answers?.Where(x => !string.IsNullOrEmpty(x.Key?.Trim()) && !string.IsNullOrEmpty(x.Value?.Trim()));
// Create quersy
return validAnsers != null && validAnsers.Count() > 0
? $"request=user_minianswer&{string.Join("&", validAnsers.Select(x => $"{x.Key}={WebUtility.UrlEncode(x.Value)}"))}&authcookie={SessionCookie}{MerchantId}"
: $"request=user_minianswer&authcookie={SessionCookie}{MerchantId}";
}
}
}

View file

@ -0,0 +1,34 @@
using System.Collections.Generic;
using System.Runtime.Serialization;
namespace TINK.Repository.Response
{
[DataContract]
public class MiniSurveyResponse
{
[DataContract]
public class Question
{
[DataMember]
public string quest_text { get; private set; }
[DataMember]
public string type { get; private set; }
[DataMember]
public Dictionary<string, string> query { get; private set; }
}
[DataMember]
public string title { get; private set; }
[DataMember]
public string subtitle { get; private set; }
[DataMember]
public string footer { get; private set; }
[DataMember]
public Dictionary<string, Question> questions { get; private set; }
}
}

View file

@ -1,4 +1,6 @@

using System.Runtime.Serialization;
namespace TINK.Repository.Response
{
/// <summary>
@ -6,5 +8,8 @@ namespace TINK.Repository.Response
/// </summary>
public class ReservationCancelReturnResponse : BikesReservedOccupiedResponse
{
/// <summary> Mini survey.</summary>
[DataMember]
public MiniSurveyResponse user_miniquery { get; private set; }
}
}