OOCalendarAPI.swift 5.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. //
  2. // OOCalendarAPI.swift
  3. // O2Platform
  4. //
  5. // Created by FancyLou on 2018/7/24.
  6. // Copyright © 2018 zoneland. All rights reserved.
  7. //
  8. import Moya
  9. enum OOCalendarAPI {
  10. case myCalendarList
  11. case filterCalendarEventList(OOCalendarEventFilter)
  12. case getCalendar(String)
  13. case saveCalendar(OOCalendarInfo)
  14. case deleteCalendar(String)
  15. case getPublicCalendarList // 日历广场
  16. case followCalendar(String)
  17. case followCalendarCancel(String)
  18. case saveCalendarEvent(OOCalendarEventInfo)
  19. case updateCalendarEventSingle(String, OOCalendarEventInfo)
  20. case updateCalendarEventAfter(String, OOCalendarEventInfo)
  21. case updateCalendarEventAll(String, OOCalendarEventInfo)
  22. case deleteCalendarEventSingle(String)
  23. case deleteCalendarEventAfter(String)
  24. case deleteCalendarEventAll(String)
  25. }
  26. // 上下文根
  27. extension OOCalendarAPI: OOAPIContextCapable {
  28. var apiContextKey: String {
  29. return "x_calendar_assemble_control"
  30. }
  31. }
  32. // 是否需要xtoken
  33. extension OOCalendarAPI: OOAccessTokenAuthorizable {
  34. var shouldAuthorize: Bool {
  35. return true
  36. }
  37. }
  38. extension OOCalendarAPI: TargetType {
  39. var baseURL: URL {
  40. let model = O2AuthSDK.shared.o2APIServer(context: .x_calendar_assemble_control)
  41. let baseURLString = "\(model?.httpProtocol ?? "http")://\(model?.host ?? ""):\(model?.port ?? 80)\(model?.context ?? "")"
  42. if let trueUrl = O2AuthSDK.shared.bindUnitTransferUrl2Mapping(url: baseURLString) {
  43. return URL(string: trueUrl)!
  44. }
  45. return URL(string: baseURLString)!
  46. }
  47. var path: String {
  48. switch self {
  49. case .myCalendarList:
  50. return "/jaxrs/calendar/list/my"
  51. case .filterCalendarEventList(_):
  52. return "/jaxrs/event/list/filter"
  53. case .getCalendar(let id):
  54. return "/jaxrs/calendar/\(id)"
  55. case .saveCalendar(_):
  56. return "/jaxrs/calendar"
  57. case .deleteCalendar(let id):
  58. return "/jaxrs/calendar/\(id)"
  59. case .getPublicCalendarList:
  60. return "/jaxrs/calendar/list/public"
  61. case .followCalendar(let id):
  62. return "/jaxrs/calendar/follow/\(id)"
  63. case .followCalendarCancel(let id):
  64. return "/jaxrs/calendar/follow/\(id)/cancel"
  65. case .saveCalendarEvent(_):
  66. return "/jaxrs/event"
  67. case .updateCalendarEventSingle(let id, _):
  68. return "/jaxrs/event/update/single/\(id)"
  69. case .updateCalendarEventAfter(let id, _):
  70. return "/jaxrs/event/update/after/\(id)"
  71. case .updateCalendarEventAll(let id, _):
  72. return "/jaxrs/event/update/all/\(id)"
  73. case .deleteCalendarEventSingle(let id):
  74. return "/jaxrs/event/single/\(id)"
  75. case .deleteCalendarEventAfter(let id):
  76. return "/jaxrs/event/after/\(id)"
  77. case .deleteCalendarEventAll(let id):
  78. return "/jaxrs/event/all/\(id)"
  79. }
  80. }
  81. var method: Moya.Method {
  82. switch self {
  83. case .myCalendarList:
  84. return .get
  85. case .filterCalendarEventList(_):
  86. return .put
  87. case .getCalendar(_):
  88. return .get
  89. case .saveCalendar(_):
  90. return .post
  91. case .deleteCalendar(_):
  92. return .delete
  93. case .getPublicCalendarList:
  94. return .get
  95. case .followCalendar(_):
  96. return .get
  97. case .followCalendarCancel(_):
  98. return .get
  99. case .saveCalendarEvent(_):
  100. return .post
  101. case .updateCalendarEventSingle(_, _):
  102. return .put
  103. case .updateCalendarEventAfter(_, _):
  104. return .put
  105. case .updateCalendarEventAll(_, _):
  106. return .put
  107. case .deleteCalendarEventSingle(_):
  108. return .delete
  109. case .deleteCalendarEventAfter(_):
  110. return .delete
  111. case .deleteCalendarEventAll(_):
  112. return .delete
  113. }
  114. }
  115. var sampleData: Data {
  116. return "".data(using: String.Encoding.utf8)!
  117. }
  118. var task: Task {
  119. switch self {
  120. case .myCalendarList:
  121. return .requestPlain
  122. case .filterCalendarEventList(let filter):
  123. return .requestParameters(parameters: filter.toJSON() ?? [:], encoding: JSONEncoding.default)
  124. case .getCalendar(_):
  125. return .requestPlain
  126. case .saveCalendar(let bean):
  127. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  128. case .deleteCalendar(_):
  129. return .requestPlain
  130. case .getPublicCalendarList:
  131. return .requestPlain
  132. case .followCalendar(_):
  133. return .requestPlain
  134. case .followCalendarCancel(_):
  135. return .requestPlain
  136. case .saveCalendarEvent(let bean):
  137. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  138. case .updateCalendarEventSingle(_, let bean):
  139. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  140. case .updateCalendarEventAfter(_, let bean):
  141. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  142. case .updateCalendarEventAll(_, let bean):
  143. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  144. case .deleteCalendarEventSingle(_):
  145. return .requestPlain
  146. case .deleteCalendarEventAfter(_):
  147. return .requestPlain
  148. case .deleteCalendarEventAll(_):
  149. return .requestPlain
  150. }
  151. }
  152. var headers: [String : String]? {
  153. return nil
  154. }
  155. }