O2AppAPI.swift 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. //
  2. // O2AppAPI.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2017/12/21.
  6. // Copyright © 2017年 zone. All rights reserved.
  7. //
  8. import Foundation
  9. import Moya
  10. // MARK:- 所有调用的API枚举
  11. enum O2AppAPI {
  12. case getNativeAppList
  13. case getPortalAppList
  14. }
  15. // MARK:- 上下文实现
  16. extension O2AppAPI:OOAPIContextCapable {
  17. var apiContextKey: String {
  18. return ""
  19. }
  20. }
  21. // MARK: - 是否需要加入x-token访问头
  22. extension O2AppAPI:OOAccessTokenAuthorizable {
  23. public var shouldAuthorize: Bool {
  24. return true
  25. }
  26. }
  27. extension O2AppAPI:TargetType {
  28. var baseURL: URL {
  29. let model = O2AuthSDK.shared.centerServerInfo()?.webServer
  30. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 80)"
  31. if let trueUrl = O2AuthSDK.shared.bindUnitTransferUrl2Mapping(url: baseURLString) {
  32. return URL(string: trueUrl)!
  33. }
  34. return URL(string: baseURLString)!
  35. }
  36. var path: String {
  37. switch self {
  38. case .getNativeAppList:
  39. return "/application.json"
  40. case .getPortalAppList:
  41. return ""
  42. }
  43. }
  44. var method: Moya.Method {
  45. return .get
  46. }
  47. var sampleData: Data {
  48. return "".data(using: String.Encoding.utf8)!
  49. }
  50. var task: Task {
  51. return .requestPlain
  52. }
  53. var headers: [String : String]? {
  54. return nil
  55. }
  56. }