PersonalAPI.swift 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. //
  2. // PersonalAPI.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2018/11/21.
  6. // Copyright © 2018 zoneland. All rights reserved.
  7. //
  8. import Moya
  9. enum PersonalAPI {
  10. case personInfo
  11. case updatePersonInfo(O2PersonInfo)
  12. case updatePersonIcon(UIImage)
  13. case meetingConfig
  14. }
  15. extension PersonalAPI: OOAPIContextCapable {
  16. var apiContextKey: String {
  17. return "x_organization_assemble_personal"
  18. }
  19. }
  20. extension PersonalAPI: OOAccessTokenAuthorizable {
  21. var shouldAuthorize: Bool {
  22. return true
  23. }
  24. }
  25. extension PersonalAPI: TargetType {
  26. var baseURL: URL {
  27. let model = O2AuthSDK.shared.o2APIServer(context: .x_organization_assemble_personal)
  28. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 80)\(model?.context ?? "")"
  29. return URL(string: baseURLString)!
  30. }
  31. var path: String {
  32. switch self {
  33. case .personInfo:
  34. return "jaxrs/person"
  35. case .updatePersonInfo(_):
  36. return "jaxrs/person"
  37. case .updatePersonIcon(_):
  38. return "jaxrs/person/icon"
  39. case .meetingConfig:
  40. return "jaxrs/definition/meetingConfig"
  41. }
  42. }
  43. var method: Moya.Method {
  44. switch self {
  45. case .personInfo, .meetingConfig:
  46. return .get
  47. case .updatePersonInfo(_), .updatePersonIcon(_):
  48. return .put
  49. }
  50. }
  51. var sampleData: Data {
  52. return "".data(using: String.Encoding.utf8)!
  53. }
  54. var task: Task {
  55. switch self {
  56. case .personInfo, .meetingConfig:
  57. return .requestPlain
  58. case .updatePersonInfo(let person):
  59. return .requestParameters(parameters: person.toJSON() ?? [:], encoding: JSONEncoding.default)
  60. case .updatePersonIcon(let image):
  61. let data = image.pngData()
  62. let formData = MultipartFormData(provider: .data(data!), name: "file",
  63. fileName: "avatar.png", mimeType: "image/png")
  64. return .uploadMultipart([formData])
  65. }
  66. }
  67. var headers: [String : String]? {
  68. return nil
  69. }
  70. }