Follow the leader
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.

37 lines
840B

  1. using System;
  2. using System.Text;
  3. using Newtonsoft.Json;
  4. namespace Leadercraft.Server
  5. {
  6. internal class LeadercraftResult<T>
  7. {
  8. private string _responseJson;
  9. public readonly int StatusCode;
  10. public bool IsError { get => StatusCode < 200 || StatusCode > 299; }
  11. public ResultStruct<T> ParseResult()
  12. {
  13. return JsonConvert.DeserializeObject<ResultStruct<T>>(_responseJson);
  14. }
  15. public ResultStruct<string> ParseError()
  16. {
  17. return JsonConvert.DeserializeObject<ResultStruct<string>>(_responseJson);
  18. }
  19. public LeadercraftResult(string response, int status = 200)
  20. {
  21. this._responseJson = response;
  22. this.StatusCode = status;
  23. }
  24. public LeadercraftResult(byte[] response, int status = 200)
  25. {
  26. this._responseJson = Encoding.ASCII.GetString(response);
  27. this.StatusCode = status;
  28. }
  29. }
  30. }