蛋蛋星球-制度模式
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

109 行
2.8 KiB

  1. package jpush
  2. import (
  3. "bytes"
  4. "encoding/json"
  5. "strings"
  6. )
  7. func (c *Client) DeviceView(registrationId string) (map[string]interface{}, error) {
  8. link := c.deviceUrl + "/v3/devices/" + registrationId
  9. resp, err := c.request("GET", link, nil, false)
  10. if err != nil {
  11. return nil, err
  12. }
  13. return resp.Map()
  14. }
  15. func (c *Client) DeviceRequest(registrationId string, req *DeviceSettingRequest) ([]byte, error) {
  16. link := c.deviceUrl + "/v3/devices/" + registrationId
  17. buf, err := json.Marshal(req)
  18. if err != nil {
  19. return nil, err
  20. }
  21. resp, err := c.request("POST", link, bytes.NewReader(buf), false)
  22. if err != nil {
  23. return nil, err
  24. }
  25. return resp.Bytes(), nil
  26. }
  27. func (c *Client) DeviceEmptyTagsRequest(registrationId string, req *DeviceSettingEmptyTagsRequest) ([]byte, error) {
  28. link := c.deviceUrl + "/v3/devices/" + registrationId
  29. buf, err := json.Marshal(req)
  30. if err != nil {
  31. return nil, err
  32. }
  33. resp, err := c.request("POST", link, bytes.NewReader(buf), false)
  34. if err != nil {
  35. return nil, err
  36. }
  37. return resp.Bytes(), nil
  38. }
  39. func (c *Client) DeviceGetWithAlias(alias string, platforms []string) (map[string]interface{}, error) {
  40. link := c.deviceUrl + "/v3/aliases/" + alias
  41. if len(platforms) > 0 {
  42. link += "?platform=" + strings.Join(platforms, ",")
  43. }
  44. resp, err := c.request("GET", link, nil, false)
  45. if err != nil {
  46. return nil, err
  47. }
  48. return resp.Map()
  49. }
  50. func (c *Client) DeviceDeleteAlias(alias string) ([]byte, error) {
  51. link := c.deviceUrl + "/v3/aliases/" + alias
  52. resp, err := c.request("DELETE", link, nil, false)
  53. if err != nil {
  54. return nil, err
  55. }
  56. return resp.Bytes(), nil
  57. }
  58. func (c *Client) DeviceGetTags() (map[string]interface{}, error) {
  59. link := c.deviceUrl + "/v3/tags/"
  60. resp, err := c.request("GET", link, nil, false)
  61. if err != nil {
  62. return nil, err
  63. }
  64. return resp.Map()
  65. }
  66. func (c *Client) DeviceCheckDeviceWithTag(tag, registrationId string) (map[string]interface{}, error) {
  67. link := c.deviceUrl + "/v3/tags/" + tag + "/registration_ids/" + registrationId
  68. resp, err := c.request("GET", link, nil, false)
  69. if err != nil {
  70. return nil, err
  71. }
  72. return resp.Map()
  73. }
  74. func (c *Client) DeviceBindTags(tag string, req *DeviceBindTagsRequest) ([]byte, error) {
  75. link := c.deviceUrl + "/v3/tags/" + tag
  76. params := make(map[string]interface{})
  77. params["registration_ids"] = req
  78. buf, err := json.Marshal(params)
  79. if err != nil {
  80. return nil, err
  81. }
  82. resp, err := c.request("POST", link, bytes.NewReader(buf), false)
  83. if err != nil {
  84. return nil, err
  85. }
  86. return resp.Bytes(), nil
  87. }
  88. func (c *Client) DeviceDeleteTag(tag string, platforms []string) ([]byte, error) {
  89. link := c.deviceUrl + "/v3/tags/" + tag
  90. if len(platforms) > 0 {
  91. link += "?platform=" + strings.Join(platforms, ",")
  92. }
  93. resp, err := c.request("DELETE", link, nil, false)
  94. if err != nil {
  95. return nil, err
  96. }
  97. return resp.Bytes(), nil
  98. }