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