OOWorkAPI.swift 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. //
  2. // OOWorkAPI.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2018/3/13.
  6. // Copyright © 2018年 zone. All rights reserved.
  7. //
  8. import Foundation
  9. import Moya
  10. // MARK:- 所有调用的API枚举
  11. enum OOWorkAPI {
  12. case createTask(String,Dictionary<String,String>)
  13. case getWork(String)//获取工作对象 如果工作已经结束了 500错误
  14. }
  15. // MARK:- 上下文实现
  16. extension OOWorkAPI:OOAPIContextCapable {
  17. var apiContextKey: String {
  18. return "x_processplatform_assemble_surface"
  19. }
  20. }
  21. // MARK: - 是否需要加入x-token访问头
  22. extension OOWorkAPI:OOAccessTokenAuthorizable {
  23. public var shouldAuthorize: Bool {
  24. return true
  25. }
  26. }
  27. extension OOWorkAPI:TargetType {
  28. var baseURL: URL {
  29. let model = O2AuthSDK.shared.o2APIServer(context: .x_processplatform_assemble_surface)
  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 .createTask(let processId,_):
  36. return "/jaxrs/work/process/\(processId)"
  37. case .getWork(let workId):
  38. return "/jaxrs/work/\(workId)"
  39. }
  40. }
  41. var method: Moya.Method {
  42. switch self {
  43. case .createTask(_,_):
  44. return .post
  45. case .getWork(_):
  46. return .get
  47. }
  48. }
  49. var sampleData: Data {
  50. return "".data(using: String.Encoding.utf8)!
  51. }
  52. var task: Task {
  53. switch self {
  54. case .createTask(_,let param):
  55. return .requestParameters(parameters: param, encoding: JSONEncoding.default)
  56. default:
  57. return .requestPlain
  58. }
  59. }
  60. var headers: [String : String]? {
  61. return nil
  62. }
  63. }