O2AppAPI.swift 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 ?? 0)"
  31. return URL(string: baseURLString)!
  32. }
  33. var path: String {
  34. switch self {
  35. case .getNativeAppList:
  36. return "/application.json"
  37. case .getPortalAppList:
  38. return ""
  39. }
  40. }
  41. var method: Moya.Method {
  42. return .get
  43. }
  44. var sampleData: Data {
  45. return "".data(using: String.Encoding.utf8)!
  46. }
  47. var task: Task {
  48. return .requestPlain
  49. }
  50. var headers: [String : String]? {
  51. return nil
  52. }
  53. }