JPushAPI.swift 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. //
  2. // JPushAPI.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2019/11/8.
  6. // Copyright © 2019 zoneland. All rights reserved.
  7. //
  8. import Moya
  9. // x_jpush_assemble_control 极光推送模块
  10. enum JPushAPI {
  11. case bindDevice(JPushDevice)
  12. case unBindDevice(String)
  13. }
  14. // 上下文根
  15. extension JPushAPI: OOAPIContextCapable {
  16. var apiContextKey: String {
  17. return "x_jpush_assemble_control"
  18. }
  19. }
  20. // 是否需要xtoken
  21. extension JPushAPI: OOAccessTokenAuthorizable {
  22. var shouldAuthorize: Bool {
  23. return true
  24. }
  25. }
  26. extension JPushAPI: TargetType {
  27. var baseURL: URL {
  28. let model = O2AuthSDK.shared.o2APIServer(context: .x_jpush_assemble_control)
  29. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 0)\(model?.context ?? "")"
  30. return URL(string: baseURLString)!
  31. }
  32. var path: String {
  33. switch self {
  34. case .bindDevice(_):
  35. return "/jaxrs/device/bind"
  36. case .unBindDevice(let deviceName):
  37. return "/jaxrs/device/unbind/\(deviceName)/ios"
  38. }
  39. }
  40. var method: Moya.Method {
  41. switch self {
  42. case .bindDevice(_):
  43. return .post
  44. case .unBindDevice(_):
  45. return .delete
  46. }
  47. }
  48. var sampleData: Data {
  49. return "".data(using: String.Encoding.utf8)!
  50. }
  51. var task: Task {
  52. switch self {
  53. case .bindDevice(let device):
  54. return .requestParameters(parameters: device.toJSON()!, encoding: JSONEncoding.default)
  55. case .unBindDevice:
  56. return .requestPlain
  57. }
  58. }
  59. var headers: [String : String]? {
  60. return nil
  61. }
  62. }