BaseDingTalkRequest.cs 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. using System;
  2. using System.Collections.Generic;
  3. using Top.Api;
  4. namespace DingTalk.Api
  5. {
  6. /// <summary>
  7. /// 基础TOP请求类,存放一些通用的请求参数。
  8. /// </summary>
  9. public abstract class BaseDingTalkRequest<T> : IDingTalkRequest<T> where T : DingTalkResponse
  10. {
  11. /// <summary>
  12. /// HTTP请求URL参数
  13. /// </summary>
  14. internal TopDictionary otherParams;
  15. /// <summary>
  16. /// HTTP请求头参数
  17. /// </summary>
  18. private TopDictionary headerParams;
  19. private String httpMethod = "POST";
  20. public void AddOtherParameter(string key, string value)
  21. {
  22. if (this.otherParams == null)
  23. {
  24. this.otherParams = new TopDictionary();
  25. }
  26. this.otherParams.Add(key, value);
  27. }
  28. public void AddHeaderParameter(string key, string value)
  29. {
  30. GetHeaderParameters().Add(key, value);
  31. }
  32. public IDictionary<string, string> GetHeaderParameters()
  33. {
  34. if (this.headerParams == null)
  35. {
  36. this.headerParams = new TopDictionary();
  37. }
  38. return this.headerParams;
  39. }
  40. public abstract string GetApiName();
  41. public abstract string GetApiCallType();
  42. public abstract void Validate();
  43. public abstract IDictionary<string, string> GetParameters();
  44. public void SetHttpMethod(String httpMethod) {
  45. this.httpMethod = httpMethod;
  46. }
  47. public string GetHttpMethod()
  48. {
  49. return httpMethod;
  50. }
  51. }
  52. }