model.py 7.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181
  1. #! usr/bin/python
  2. # coding=utf-8
  3. # Copyright 2014 Baidu, Inc.
  4. #
  5. # Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file
  6. # except in compliance with the License. You may obtain a copy of the License at
  7. #
  8. # http://www.apache.org/licenses/LICENSE-2.0
  9. #
  10. # Unless required by applicable law or agreed to in writing, software distributed under the
  11. # License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND,
  12. # either express or implied. See the License for the specific language governing permissions
  13. # and limitations under the License.
  14. """
  15. This module defines some Response classes for BTS
  16. """
  17. from baidubce.bce_response import BceResponse
  18. class CreateSignatureResponse(BceResponse):
  19. """
  20. Create Signature Response
  21. """
  22. def __init__(self, bce_response):
  23. super(CreateSignatureResponse, self).__init__()
  24. self.signature_id = str(bce_response.signature_id)
  25. self.status = str(bce_response.status)
  26. self.metadata = bce_response.metadata
  27. class GetSignatureResponse(BceResponse):
  28. """
  29. Get Signature Response
  30. """
  31. def __init__(self, bce_response):
  32. super(GetSignatureResponse, self).__init__()
  33. self.signature_id = str(bce_response.signature_id)
  34. self.user_id = str(bce_response.user_id)
  35. self.content = str(bce_response.content)
  36. self.country_type = str(bce_response.country_type)
  37. self.content_type = str(bce_response.content_type)
  38. self.review = str(bce_response.review)
  39. self.status = str(bce_response.status)
  40. self.metadata = bce_response.metadata
  41. class CreateTemplateResponse(BceResponse):
  42. """
  43. Create Template Response
  44. """
  45. def __init__(self, bce_response):
  46. super(CreateTemplateResponse, self).__init__()
  47. self.template_id = str(bce_response.template_id)
  48. self.status = str(bce_response.status)
  49. self.metadata = bce_response.metadata
  50. class GetTemplateResponse(BceResponse):
  51. """
  52. Get Template Response
  53. """
  54. def __init__(self, bce_response):
  55. super(GetTemplateResponse, self).__init__()
  56. self.template_id = str(bce_response.template_id)
  57. self.user_id = str(bce_response.user_id)
  58. self.name = str(bce_response.name)
  59. self.content = str(bce_response.content)
  60. self.sms_type = str(bce_response.sms_type)
  61. self.description = str(bce_response.description)
  62. self.review = str(bce_response.review)
  63. self.status = str(bce_response.status)
  64. self.country_type = str(bce_response.country_type)
  65. self.metadata = bce_response.metadata
  66. class QueryQuotaResponse(BceResponse):
  67. """
  68. Query Quota Response
  69. """
  70. def __init__(self, bce_response):
  71. super(QueryQuotaResponse, self).__init__()
  72. self.quota_per_day = bce_response.quota_per_day
  73. self.quota_per_month = bce_response.quota_per_month
  74. self.quota_remain_today = bce_response.quota_remain_today
  75. self.quota_remain_this_month = bce_response.quota_remain_this_month
  76. self.apply_quota_per_day = bce_response.apply_quota_per_day
  77. self.apply_quota_per_month = bce_response.apply_quota_per_month
  78. self.apply_check_status = bce_response.apply_check_status
  79. self.check_reply = bce_response.check_reply
  80. self.rate_limit_per_mobile_per_sign_by_minute = bce_response.rate_limit_per_mobile_per_sign_by_minute
  81. self.rate_limit_per_mobile_per_sign_by_hour = bce_response.rate_limit_per_mobile_per_sign_by_hour
  82. self.rate_limit_per_mobile_per_sign_by_day = bce_response.reate_limit_per_mobile_per_sign_by_day
  83. self.rate_limit_white_list = bce_response.rate_limit_white_list
  84. self.metadata = bce_response.metadata
  85. class GetMobileBlackResponse(BceResponse):
  86. """
  87. Get Mobile Black Response
  88. """
  89. def __init__(self, bce_response):
  90. super(GetMobileBlackResponse, self).__init__()
  91. self.total_count = bce_response.total_count
  92. self.page_no = bce_response.page_no
  93. self.page_size = bce_response.page_size
  94. self.black_lists = bce_response.blacklists
  95. self.metadata = bce_response.metadata
  96. class ListStatisticsResponse(BceResponse):
  97. """
  98. Get Statistics Information Response as List
  99. """
  100. def __init__(self, bce_response):
  101. super(ListStatisticsResponse, self).__init__()
  102. self.statistics_results = list(map(self.__result_trans, bce_response.statistics_results))
  103. def __result_trans(self, statistics_result):
  104. res = {
  105. 'datetime': statistics_result.datetime,
  106. 'country_alpha2_code': statistics_result.country_alpha2_code,
  107. 'submit_count': statistics_result.submit_count,
  108. 'submit_long_count': statistics_result.submit_long_count,
  109. 'response_success_count': statistics_result.response_success_count,
  110. 'response_success_proportion': statistics_result.response_success_proportion,
  111. 'deliver_success_count': statistics_result.deliver_success_count,
  112. 'deliver_success_long_count': statistics_result.deliver_success_long_count,
  113. 'deliver_success_proportion': statistics_result.deliver_success_proportion,
  114. 'deliver_failure_count': statistics_result.deliver_failure_count,
  115. 'deliver_failure_proportion': statistics_result.deliver_failure_proportion,
  116. 'receipt_proportion': statistics_result.receipt_proportion,
  117. 'unknown_count': statistics_result.unknown_count,
  118. 'unknown_proportion': statistics_result.unknown_proportion,
  119. 'response_timeout_count': statistics_result.response_timeout_count,
  120. 'unknown_error_count': statistics_result.unknown_error_count,
  121. 'not_exist_count': statistics_result.not_exist_count,
  122. 'signature_or_template_count': statistics_result.signature_or_template_count,
  123. 'abnormal_count': statistics_result.abnormal_count,
  124. 'overclocking_count': statistics_result.overclocking_count,
  125. 'other_error_count': statistics_result.other_error_count,
  126. 'blacklist_count': statistics_result.blacklist_count,
  127. 'route_error_count': statistics_result.route_error_count,
  128. 'issue_failure_count': statistics_result.issue_failure_count,
  129. 'parameter_error_count': statistics_result.parameter_error_count,
  130. 'illegal_word_count': statistics_result.illegal_word_count,
  131. 'anomaly_count': statistics_result.anomaly_count
  132. }
  133. return res
  134. class GetPrepaidPackageResponse(BceResponse):
  135. """
  136. Get Prepaid Packages Information Response as List
  137. """
  138. def __init__(self, bce_response):
  139. super(GetPrepaidPackageResponse, self).__init__()
  140. self.total_count = bce_response.total_count
  141. self.prepaid_packages = list(map(self.__result_trans, bce_response.prepaid_packages))
  142. def __result_trans(self, prepaid_package):
  143. res = {
  144. 'package_id': prepaid_package.package_id,
  145. 'name': prepaid_package.name,
  146. 'country_type': prepaid_package.country_type,
  147. 'capacity': prepaid_package.capacity,
  148. 'remaining_capacity': prepaid_package.remaining_capacity,
  149. 'package_status': prepaid_package.package_status,
  150. 'purchase_date': prepaid_package.purchase_date,
  151. 'expiry_date': prepaid_package.expiry_date
  152. }
  153. return res