OOHotpicAPI.swift 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // HotpicAPI.swift
  3. // o2app
  4. //
  5. // Created by 刘振兴 on 2017/12/6.
  6. // Copyright © 2017年 zone. All rights reserved.
  7. //
  8. import Foundation
  9. import Moya
  10. // MARK:- 所有调用的API枚举
  11. enum OOHotpicAPI {
  12. case allHotpic(page:Int,count:Int)
  13. case allHotpicHome(CommonPageParameter)
  14. case hotpicImageSize(id:String,size:Int)
  15. case hotpicImageInfo(id:String)
  16. }
  17. // MARK:- 上下文实现
  18. extension OOHotpicAPI:OOAPIContextCapable {
  19. var apiContextKey: String {
  20. return "x_hotpic_assemble_control"
  21. }
  22. }
  23. // MARK: - 是否需要加入x-token访问头
  24. extension OOHotpicAPI:OOAccessTokenAuthorizable {
  25. public var shouldAuthorize: Bool {
  26. return true
  27. }
  28. }
  29. // MARK: - 扩展API Moya实现
  30. extension OOHotpicAPI:TargetType {
  31. var baseURL: URL {
  32. let model = O2AuthSDK.shared.o2APIServer(context: .x_hotpic_assemble_control)
  33. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 0)\(model?.context ?? "")"
  34. return URL(string: baseURLString)!
  35. }
  36. var path: String {
  37. switch self {
  38. case .allHotpic(let page,let count):
  39. return "/jaxrs/user/hotpic/filter/list/page/\(page)/count/\(count)"
  40. case .allHotpicHome(let parameter):
  41. return "/jaxrs/user/hotpic/filter/list/page/\(parameter.currentPageNo)/count/\(parameter.countByPage)"
  42. case .hotpicImageInfo(let imageId):
  43. return "servlet/picture/\(imageId)"
  44. case .hotpicImageSize(let imageId, let size):
  45. return "/servlet/picture/\(imageId)/size/\(size)"
  46. }
  47. }
  48. var method: Moya.Method {
  49. switch self {
  50. case .allHotpicHome(_),.allHotpic(_,_):
  51. return .put
  52. default:
  53. return .get
  54. }
  55. }
  56. var sampleData: Data {
  57. return "".data(using: String.Encoding.utf8)!
  58. }
  59. var task: Task {
  60. switch self {
  61. case .allHotpic(_,_):
  62. return .requestPlain
  63. case .allHotpicHome(_):
  64. return .requestPlain
  65. case .hotpicImageInfo(_):
  66. return .requestPlain
  67. case .hotpicImageSize(_,_):
  68. return .requestPlain
  69. }
  70. }
  71. var headers: [String : String]? {
  72. return nil
  73. }
  74. }