12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485 |
- //
- // O2QuerySurfaceAPI.swift
- // O2Platform
- //
- // Created by FancyLou on 2021/5/25.
- // Copyright © 2021 zoneland. All rights reserved.
- //
- import Foundation
- import Moya
- enum O2QuerySurfaceAPI {
- // 搜索
- case segmentSearch(String)
- // 根据搜索的结果id 显示指定的搜索条目
- case segmentListEntry([String])
-
- }
- // MARK: - 通讯录上下文
- extension O2QuerySurfaceAPI:OOAPIContextCapable {
- var apiContextKey: String {
- return "x_query_assemble_surface"
- }
- }
- // MARK: - 是否需要加入x-token访问头
- extension O2QuerySurfaceAPI:OOAccessTokenAuthorizable {
- public var shouldAuthorize: Bool {
- return true
- }
- }
- // MARK: - 扩展API
- extension O2QuerySurfaceAPI:TargetType {
-
- var baseURL: URL {
- let model = O2AuthSDK.shared.o2APIServer(context: .x_query_assemble_surface)
- let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 80)\(model?.context ?? "")"
- if let trueUrl = O2AuthSDK.shared.bindUnitTransferUrl2Mapping(url: baseURLString) {
- return URL(string: trueUrl)!
- }
- return URL(string: baseURLString)!
- }
-
- var path: String {
- switch self {
- case .segmentSearch(let key):
- return "/jaxrs/segment/key/\(key)"
- case .segmentListEntry(_):
- return "/jaxrs/segment/list/entry"
- }
- }
-
- var method: Moya.Method {
- switch self {
- case .segmentSearch(_):
- return .get
- case .segmentListEntry(_):
- return .post
- }
- }
-
- var sampleData: Data {
- return "".data(using: String.Encoding.utf8)!
- }
-
- var task: Task {
- switch self {
- case .segmentSearch(_):
- return .requestPlain
- case .segmentListEntry(let list):
- return .requestParameters(parameters: ["entryList": list], encoding: JSONEncoding.default)
- }
- }
-
- var headers: [String : String]? {
- return nil
- }
-
-
-
- }
|