PackageReviewService.cs 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. using System.Collections.Generic;
  2. using System.Globalization;
  3. using System.Threading;
  4. using System.Threading.Tasks;
  5. using MediaBrowser.Common.Constants;
  6. using MediaBrowser.Common.Net;
  7. using ServiceStack.ServiceHost;
  8. namespace MediaBrowser.Api
  9. {
  10. /// <summary>
  11. /// Class InstallPackage
  12. /// </summary>
  13. [Route("/PackageReviews/{Id}", "POST")]
  14. [Api(("Creates or updates a package review"))]
  15. public class CreateReviewRequest : IReturnVoid
  16. {
  17. /// <summary>
  18. /// Gets or sets the Id.
  19. /// </summary>
  20. /// <value>The Id.</value>
  21. [ApiMember(Name = "Id", Description = "Package Id", IsRequired = true, DataType = "int", ParameterType = "path", Verb = "POST")]
  22. public int Id { get; set; }
  23. /// <summary>
  24. /// Gets or sets the rating.
  25. /// </summary>
  26. /// <value>The review.</value>
  27. [ApiMember(Name = "Rating", Description = "The rating value (1-5)", IsRequired = true, DataType = "int", ParameterType = "query", Verb = "POST")]
  28. public int Rating { get; set; }
  29. /// <summary>
  30. /// Gets or sets the recommend value.
  31. /// </summary>
  32. /// <value>Whether or not this review recommends this item.</value>
  33. [ApiMember(Name = "Recommend", Description = "Whether or not this review recommends this item", IsRequired = true, DataType = "bool", ParameterType = "query", Verb = "POST")]
  34. public bool Recommend { get; set; }
  35. /// <summary>
  36. /// Gets or sets the title.
  37. /// </summary>
  38. /// <value>The title.</value>
  39. [ApiMember(Name = "Title", Description = "Optional short description of review.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
  40. public string Title { get; set; }
  41. /// <summary>
  42. /// Gets or sets the full review.
  43. /// </summary>
  44. /// <value>The full review.</value>
  45. [ApiMember(Name = "Review", Description = "Optional full review.", IsRequired = false, DataType = "string", ParameterType = "query", Verb = "POST")]
  46. public string Review { get; set; }
  47. }
  48. public class PackageReviewService : BaseApiService
  49. {
  50. private readonly IHttpClient _httpClient;
  51. private readonly INetworkManager _netManager;
  52. public PackageReviewService(IHttpClient client, INetworkManager net)
  53. {
  54. _httpClient = client;
  55. _netManager = net;
  56. }
  57. public void Post(CreateReviewRequest request)
  58. {
  59. var review = new Dictionary<string, string>
  60. { { "id", request.Id.ToString(CultureInfo.InvariantCulture) },
  61. { "mac", _netManager.GetMacAddress() },
  62. { "rating", request.Rating.ToString(CultureInfo.InvariantCulture) },
  63. { "recommend", request.Recommend.ToString() },
  64. { "title", request.Title },
  65. { "review", request.Review },
  66. };
  67. Task.WaitAll(_httpClient.Post(Constants.MbAdminUrl + "/service/packageReview/update", review, CancellationToken.None));
  68. }
  69. }
  70. }