OOApplicationAPI.swift 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  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. 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 .availableIdentityWithProcess(let processId):
  47. return "/jaxrs/process/list/available/identity/process/\(processId)"
  48. case .startProcess(let processId, _, _):
  49. return "/jaxrs/work/process/\(processId)"
  50. case .icon(let applicationId):
  51. return "/jaxrs/application/\(applicationId)/icon"
  52. }
  53. }
  54. var method: Moya.Method {
  55. switch self {
  56. case .startProcess(_, _, _):
  57. return .post
  58. default:
  59. return .get
  60. }
  61. }
  62. var sampleData: Data {
  63. return "".data(using: String.Encoding.utf8)!
  64. }
  65. var task: Task {
  66. switch self {
  67. case .startProcess(_, let identity, let title):
  68. return .requestParameters(parameters: ["identity": identity, "title": title], encoding: JSONEncoding.default)
  69. default:
  70. return .requestPlain
  71. }
  72. }
  73. var headers: [String : String]? {
  74. return nil
  75. }
  76. }