aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Api/PackageReviewService.cs
blob: 1aca596c0e64529a881d06bfefaff9a78a57322b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
using System.Collections.Generic;
using System.Globalization;
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Common.Constants;
using MediaBrowser.Common.Net;
using ServiceStack.ServiceHost;

namespace MediaBrowser.Api
{
    /// <summary>
    /// Class InstallPackage
    /// </summary>
    [Route("/PackageReviews/{Id}", "POST")]
    [Api(("Creates or updates a package review"))]
    public class CreateReviewRequest : IReturnVoid
    {
        /// <summary>
        /// Gets or sets the Id.
        /// </summary>
        /// <value>The Id.</value>
        [ApiMember(Name = "Id", Description = "Package Id", IsRequired = true, DataType = "int", ParameterType = "path", Verb = "POST")]
        public int Id { get; set; }

        /// <summary>
        /// Gets or sets the rating.
        /// </summary>
        /// <value>The review.</value>
        [ApiMember(Name = "Rating", Description = "The rating value (1-5)", IsRequired = true, DataType = "int", ParameterType = "query", Verb = "POST")]
        public int Rating { get; set; }

        /// <summary>
        /// Gets or sets the recommend value.
        /// </summary>
        /// <value>Whether or not this review recommends this item.</value>
        [ApiMember(Name = "Recommend", Description = "Whether or not this review recommends this item", IsRequired = true, DataType = "bool", ParameterType = "query", Verb = "POST")]
        public bool Recommend { get; set; }

        /// <summary>
        /// Gets or sets the title.
        /// </summary>
        /// <value>The title.</value>
        [ApiMember(Name = "Title", Description = "Optional short description of review.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
        public string Title { get; set; }

        /// <summary>
        /// Gets or sets the full review.
        /// </summary>
        /// <value>The full review.</value>
        [ApiMember(Name = "Review", Description = "Optional full review.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
        public string Review { get; set; }
    }


    public class PackageReviewService : BaseApiService
    {
        private readonly IHttpClient _httpClient;
        private readonly INetworkManager _netManager;

        public PackageReviewService(IHttpClient client, INetworkManager net)
        {
            _httpClient = client;
            _netManager = net;
        }

        public void Post(CreateReviewRequest request)
        {
            var review = new Dictionary<string, string>
                             { { "id", request.Id.ToString(CultureInfo.InvariantCulture) },
                               { "mac", _netManager.GetMacAddress() },
                               { "rating", request.Rating.ToString(CultureInfo.InvariantCulture) },
                               { "recommend", request.Recommend.ToString() },
                               { "title", request.Title },
                               { "review", request.Review },
                             };

            Task.WaitAll(_httpClient.Post(Constants.MbAdminUrl + "/service/packageReview/update", review, CancellationToken.None));
        }
    }
}