using System;
using System.Collections.Generic;
using System.Threading.Tasks;
using Plugins.Countly.Helpers;
using Plugins.Countly.Models;
namespace Plugins.Countly.Services.Impls.Actual
{
public class StarRatingCountlyService : IStarRatingCountlyService
{
private readonly IEventCountlyService _eventCountlyService;
public StarRatingCountlyService(IEventCountlyService eventCountlyService)
{
_eventCountlyService = eventCountlyService;
}
///
/// Sends app rating to the server.
///
///
///
/// Rating should be from 1 to 5
///
public async Task ReportStarRatingAsync(string platform, string appVersion, int rating)
{
if (rating < 1 || rating > 5)
{
return new CountlyResponse
{
IsSuccess = false,
ErrorMessage = "Please provide rating from 1 to 5"
};
}
var segment =
new StarRatingSegment
{
Platform = platform,
AppVersion = appVersion,
Rating = rating,
};
return await _eventCountlyService.ReportCustomEventAsync(
CountlyEventModel.StarRatingEvent, segment.ToDictionary(),
null, null, null);
}
///
/// Custom Segmentation for Star Rating event.
///
[Serializable]
struct StarRatingSegment
{
public string Platform { get; set; }
public string AppVersion { get; set; }
public int Rating { get; set; }
public IDictionary ToDictionary()
{
return new Dictionary()
{
{"platform", Platform},
{"app_version", AppVersion},
{"rating", Rating},
};
}
}
}
}