OOApplicationAPI.swift 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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. import O2OA_Auth_SDK
  11. // MARK:- 所有调用的API枚举
  12. enum OOApplicationAPI {
  13. case applicationList
  14. case applicationOnlyList
  15. case applicationItem(String)
  16. case availableIdentityWithProcess(String)
  17. case startProcess(String, String, String) // processId identity title
  18. }
  19. // MARK:- 上下文实现
  20. extension OOApplicationAPI:OOAPIContextCapable {
  21. var apiContextKey: String {
  22. return "x_processplatform_assemble_surface"
  23. }
  24. }
  25. // MARK: - 是否需要加入x-token访问头
  26. extension OOApplicationAPI:OOAccessTokenAuthorizable {
  27. public var shouldAuthorize: Bool {
  28. return true
  29. }
  30. }
  31. extension OOApplicationAPI:TargetType {
  32. var baseURL: URL {
  33. let model = O2AuthSDK.shared.o2APIServer(context: .x_processplatform_assemble_surface)
  34. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 0)\(model?.context ?? "")"
  35. return URL(string: baseURLString)!
  36. }
  37. var path: String {
  38. switch self {
  39. case .applicationList:
  40. return "/jaxrs/application/list/complex"
  41. case .applicationOnlyList:
  42. return "/jaxrs/application/list"
  43. case .applicationItem(let appId):
  44. return "/jaxrs/process/list/application/\(appId)"
  45. case .availableIdentityWithProcess(let processId):
  46. return "/jaxrs/process/list/available/identity/process/\(processId)"
  47. case .startProcess(let processId, _, _):
  48. return "/jaxrs/work/process/\(processId)"
  49. }
  50. }
  51. var method: Moya.Method {
  52. switch self {
  53. case .startProcess(_, _, _):
  54. return .post
  55. default:
  56. return .get
  57. }
  58. }
  59. var sampleData: Data {
  60. return "".data(using: String.Encoding.utf8)!
  61. }
  62. var task: Task {
  63. switch self {
  64. case .startProcess(_, let identity, let title):
  65. return .requestParameters(parameters: ["identity": identity, "title": title], encoding: JSONEncoding.default)
  66. default:
  67. return .requestPlain
  68. }
  69. }
  70. var headers: [String : String]? {
  71. return nil
  72. }
  73. }