OOApplicationAPI.swift 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. }
  17. // MARK:- 上下文实现
  18. extension OOApplicationAPI:OOAPIContextCapable {
  19. var apiContextKey: String {
  20. return "x_processplatform_assemble_surface"
  21. }
  22. }
  23. // MARK: - 是否需要加入x-token访问头
  24. extension OOApplicationAPI:OOAccessTokenAuthorizable {
  25. public var shouldAuthorize: Bool {
  26. return true
  27. }
  28. }
  29. extension OOApplicationAPI:TargetType {
  30. var baseURL: URL {
  31. let model = O2AuthSDK.shared.o2APIServer(context: .x_processplatform_assemble_surface)
  32. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 0)\(model?.context ?? "")"
  33. return URL(string: baseURLString)!
  34. }
  35. var path: String {
  36. switch self {
  37. case .applicationList:
  38. return "/jaxrs/application/list/complex"
  39. case .applicationOnlyList:
  40. return "/jaxrs/application/list"
  41. case .applicationItem(let appId):
  42. return "/jaxrs/process/list/application/\(appId)"
  43. }
  44. }
  45. var method: Moya.Method {
  46. return .get
  47. }
  48. var sampleData: Data {
  49. return "".data(using: String.Encoding.utf8)!
  50. }
  51. var task: Task {
  52. return .requestPlain
  53. }
  54. var headers: [String : String]? {
  55. return nil
  56. }
  57. }