APIMessage.py 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  1. # coding=utf-8
  2. from Service.VivoPushService.push_admin.APIConstants import Constants
  3. class MessageDict(dict):
  4. def __getattr__(self, item):
  5. try:
  6. return self[item]
  7. except KeyError:
  8. raise AttributeError(r"'message' object has no attribute %s'" % item)
  9. def __setattr__(self, key, value):
  10. self[key] = value
  11. class PushMessage(object):
  12. tag_expression={}
  13. def __init__(self):
  14. self.__message_dict = MessageDict()
  15. def or_tags(self,or_tags):
  16. PushMessage.tag_expression[Constants.http_param_or_tags]=or_tags
  17. self.__message_dict[Constants.http_param_tag_expression] = PushMessage.tag_expression
  18. return self
  19. def and_tags(self,and_tags):
  20. PushMessage.tag_expression[Constants.http_param_and_tags]=and_tags
  21. self.__message_dict[Constants.http_param_tag_expression] = PushMessage.tag_expression
  22. return self
  23. def not_tags(self,not_tags):
  24. PushMessage.tag_expression[Constants.http_param_not_tags]=not_tags
  25. self.__message_dict[Constants.http_param_tag_expression] = PushMessage.tag_expression
  26. return self
  27. def segment_name(self, segment_name):
  28. self.__message_dict[Constants.http_param_segment_name] = segment_name
  29. self.__message_dict[Constants.http_param_tag_expression] = PushMessage.tag_expression
  30. return self
  31. def reg_id(self, reg_id):
  32. self.__message_dict[Constants.http_param_reg_id] = reg_id
  33. return self
  34. def ali_as(self, ali_as):
  35. self.__message_dict[Constants.http_param_ali_as] = ali_as
  36. return self
  37. def content(self, content):
  38. self.__message_dict[Constants.http_param_content] = content
  39. return self
  40. def title(self, title):
  41. self.__message_dict[Constants.http_param_title] = title
  42. return self
  43. def notify_type(self, notify_type):
  44. self.__message_dict[Constants.http_param_notify_type] = notify_type
  45. return self
  46. def time_to_live(self, time_to_live):
  47. self.__message_dict[Constants.http_param_time_to_live] = time_to_live
  48. return self
  49. def skip_type(self, skip_type):
  50. self.__message_dict[Constants.http_param_skip_type] = skip_type
  51. return self
  52. def skip_content(self, skip_content):
  53. self.__message_dict[Constants.http_param_skip_content] = skip_content
  54. return self
  55. def network_type(self, network_type=-1):
  56. self.__message_dict[Constants.http_param_network_type] = network_type
  57. return self
  58. def request_id(self, request_id):
  59. self.__message_dict[Constants.http_param_request_id] = request_id
  60. return self
  61. def classification(self, classification):
  62. self.__message_dict[Constants.http_param_classification] = classification
  63. return self
  64. def push_mode(self, push_mode):
  65. self.__message_dict[Constants.http_param_push_mode] = push_mode
  66. return self
  67. def client_custom_map(self, **client_custom_map):
  68. self.__message_dict[Constants.http_param_client_custom_map] = client_custom_map
  69. return self
  70. def extra(self, value1, value2):
  71. extra = {Constants.http_param_callback: value1, Constants.http_param_callback_param: value2}
  72. self.__message_dict[Constants.http_param_extra] = extra
  73. return self
  74. '''
  75. message params build method
  76. '''
  77. def message_dict(self):
  78. return self.__message_dict