OOCalendarAPI.swift 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164
  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. return URL(string: baseURLString)!
  43. }
  44. var path: String {
  45. switch self {
  46. case .myCalendarList:
  47. return "/jaxrs/calendar/list/my"
  48. case .filterCalendarEventList(_):
  49. return "/jaxrs/event/list/filter"
  50. case .getCalendar(let id):
  51. return "/jaxrs/calendar/\(id)"
  52. case .saveCalendar(_):
  53. return "/jaxrs/calendar"
  54. case .deleteCalendar(let id):
  55. return "/jaxrs/calendar/\(id)"
  56. case .getPublicCalendarList:
  57. return "/jaxrs/calendar/list/public"
  58. case .followCalendar(let id):
  59. return "/jaxrs/calendar/follow/\(id)"
  60. case .followCalendarCancel(let id):
  61. return "/jaxrs/calendar/follow/\(id)/cancel"
  62. case .saveCalendarEvent(_):
  63. return "/jaxrs/event"
  64. case .updateCalendarEventSingle(let id, _):
  65. return "/jaxrs/event/update/single/\(id)"
  66. case .updateCalendarEventAfter(let id, _):
  67. return "/jaxrs/event/update/after/\(id)"
  68. case .updateCalendarEventAll(let id, _):
  69. return "/jaxrs/event/update/all/\(id)"
  70. case .deleteCalendarEventSingle(let id):
  71. return "/jaxrs/event/single/\(id)"
  72. case .deleteCalendarEventAfter(let id):
  73. return "/jaxrs/event/after/\(id)"
  74. case .deleteCalendarEventAll(let id):
  75. return "/jaxrs/event/all/\(id)"
  76. }
  77. }
  78. var method: Moya.Method {
  79. switch self {
  80. case .myCalendarList:
  81. return .get
  82. case .filterCalendarEventList(_):
  83. return .put
  84. case .getCalendar(_):
  85. return .get
  86. case .saveCalendar(_):
  87. return .post
  88. case .deleteCalendar(_):
  89. return .delete
  90. case .getPublicCalendarList:
  91. return .get
  92. case .followCalendar(_):
  93. return .get
  94. case .followCalendarCancel(_):
  95. return .get
  96. case .saveCalendarEvent(_):
  97. return .post
  98. case .updateCalendarEventSingle(_, _):
  99. return .put
  100. case .updateCalendarEventAfter(_, _):
  101. return .put
  102. case .updateCalendarEventAll(_, _):
  103. return .put
  104. case .deleteCalendarEventSingle(_):
  105. return .delete
  106. case .deleteCalendarEventAfter(_):
  107. return .delete
  108. case .deleteCalendarEventAll(_):
  109. return .delete
  110. }
  111. }
  112. var sampleData: Data {
  113. return "".data(using: String.Encoding.utf8)!
  114. }
  115. var task: Task {
  116. switch self {
  117. case .myCalendarList:
  118. return .requestPlain
  119. case .filterCalendarEventList(let filter):
  120. return .requestParameters(parameters: filter.toJSON() ?? [:], encoding: JSONEncoding.default)
  121. case .getCalendar(_):
  122. return .requestPlain
  123. case .saveCalendar(let bean):
  124. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  125. case .deleteCalendar(_):
  126. return .requestPlain
  127. case .getPublicCalendarList:
  128. return .requestPlain
  129. case .followCalendar(_):
  130. return .requestPlain
  131. case .followCalendarCancel(_):
  132. return .requestPlain
  133. case .saveCalendarEvent(let bean):
  134. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  135. case .updateCalendarEventSingle(_, let bean):
  136. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  137. case .updateCalendarEventAfter(_, let bean):
  138. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  139. case .updateCalendarEventAll(_, let bean):
  140. return .requestParameters(parameters: bean.toJSON() ?? [:], encoding: JSONEncoding.default)
  141. case .deleteCalendarEventSingle(_):
  142. return .requestPlain
  143. case .deleteCalendarEventAfter(_):
  144. return .requestPlain
  145. case .deleteCalendarEventAll(_):
  146. return .requestPlain
  147. }
  148. }
  149. var headers: [String : String]? {
  150. return nil
  151. }
  152. }