O2QuerySurfaceAPI.swift 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485
  1. //
  2. // O2QuerySurfaceAPI.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2021/5/25.
  6. // Copyright © 2021 zoneland. All rights reserved.
  7. //
  8. import Foundation
  9. import Moya
  10. enum O2QuerySurfaceAPI {
  11. // 搜索
  12. case segmentSearch(String)
  13. // 根据搜索的结果id 显示指定的搜索条目
  14. case segmentListEntry([String])
  15. }
  16. // MARK: - 通讯录上下文
  17. extension O2QuerySurfaceAPI:OOAPIContextCapable {
  18. var apiContextKey: String {
  19. return "x_query_assemble_surface"
  20. }
  21. }
  22. // MARK: - 是否需要加入x-token访问头
  23. extension O2QuerySurfaceAPI:OOAccessTokenAuthorizable {
  24. public var shouldAuthorize: Bool {
  25. return true
  26. }
  27. }
  28. // MARK: - 扩展API
  29. extension O2QuerySurfaceAPI:TargetType {
  30. var baseURL: URL {
  31. let model = O2AuthSDK.shared.o2APIServer(context: .x_query_assemble_surface)
  32. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 80)\(model?.context ?? "")"
  33. if let trueUrl = O2AuthSDK.shared.bindUnitTransferUrl2Mapping(url: baseURLString) {
  34. return URL(string: trueUrl)!
  35. }
  36. return URL(string: baseURLString)!
  37. }
  38. var path: String {
  39. switch self {
  40. case .segmentSearch(let key):
  41. return "/jaxrs/segment/key/\(key)"
  42. case .segmentListEntry(_):
  43. return "/jaxrs/segment/list/entry"
  44. }
  45. }
  46. var method: Moya.Method {
  47. switch self {
  48. case .segmentSearch(_):
  49. return .get
  50. case .segmentListEntry(_):
  51. return .post
  52. }
  53. }
  54. var sampleData: Data {
  55. return "".data(using: String.Encoding.utf8)!
  56. }
  57. var task: Task {
  58. switch self {
  59. case .segmentSearch(_):
  60. return .requestPlain
  61. case .segmentListEntry(let list):
  62. return .requestParameters(parameters: ["entryList": list], encoding: JSONEncoding.default)
  63. }
  64. }
  65. var headers: [String : String]? {
  66. return nil
  67. }
  68. }