OOApplicationAPI.swift 3.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. //
  2. // OOApplicationAPI.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2018/3/12.
  6. // Copyright © 2018年 zone. All rights reserved.
  7. //
  8. import Foundation
  9. import Moya
  10. // MARK:- 所有调用的API枚举
  11. enum OOApplicationAPI {
  12. case applicationList
  13. case applicationOnlyList
  14. case applicationItem(String) // 更加应用获取流程列表
  15. case applicationItemWithFilter(String) //新版 根据应用获取流程列表 有移动端过滤 仅pc的流程不出现在这里
  16. case availableIdentityWithProcess(String)
  17. case startProcess(String, String, String) // processId identity title
  18. case icon(String)
  19. }
  20. // MARK:- 上下文实现
  21. extension OOApplicationAPI:OOAPIContextCapable {
  22. var apiContextKey: String {
  23. return "x_processplatform_assemble_surface"
  24. }
  25. }
  26. // MARK: - 是否需要加入x-token访问头
  27. extension OOApplicationAPI:OOAccessTokenAuthorizable {
  28. public var shouldAuthorize: Bool {
  29. return true
  30. }
  31. }
  32. extension OOApplicationAPI:TargetType {
  33. var baseURL: URL {
  34. let model = O2AuthSDK.shared.o2APIServer(context: .x_processplatform_assemble_surface)
  35. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 0)\(model?.context ?? "")"
  36. return URL(string: baseURLString)!
  37. }
  38. var path: String {
  39. switch self {
  40. case .applicationList:
  41. return "/jaxrs/application/list/complex"
  42. case .applicationOnlyList:
  43. return "/jaxrs/application/list"
  44. case .applicationItem(let appId):
  45. return "/jaxrs/process/list/application/\(appId)"
  46. case .applicationItemWithFilter(let appId):
  47. return "/jaxrs/process/list/application/\(appId)/filter"
  48. case .availableIdentityWithProcess(let processId):
  49. return "/jaxrs/process/list/available/identity/process/\(processId)"
  50. case .startProcess(let processId, _, _):
  51. return "/jaxrs/work/process/\(processId)"
  52. case .icon(let applicationId):
  53. return "/jaxrs/application/\(applicationId)/icon"
  54. }
  55. }
  56. var method: Moya.Method {
  57. switch self {
  58. case .startProcess(_, _, _), .applicationItemWithFilter(_):
  59. return .post
  60. default:
  61. return .get
  62. }
  63. }
  64. var sampleData: Data {
  65. return "".data(using: String.Encoding.utf8)!
  66. }
  67. var task: Task {
  68. switch self {
  69. case .startProcess(_, let identity, let title):
  70. return .requestParameters(parameters: ["identity": identity, "title": title], encoding: JSONEncoding.default)
  71. case .applicationItemWithFilter(_):
  72. let filter = O2ProcessFilter()
  73. filter.startableTerminal = "mobile" //移动端过滤 仅pc的流程不出现在这里
  74. return .requestParameters(parameters: filter.toJSON()!, encoding: JSONEncoding.default)
  75. default:
  76. return .requestPlain
  77. }
  78. }
  79. var headers: [String : String]? {
  80. return nil
  81. }
  82. }