No Description

ContentResource.swift 854B

1234567891011121314151617181920212223242526272829303132333435363738
  1. //
  2. // ContentResource.swift
  3. // PaiaiDataKit
  4. //
  5. // Created by ffib on 2018/12/29.
  6. // Copyright © 2018 yb. All rights reserved.
  7. //
  8. import Foundation
  9. import RxSwift
  10. import ObjectMapper
  11. struct ContentResource<Content>: Resource {
  12. typealias Model = Content
  13. var host: String
  14. var path: Interfaces
  15. var parameter: Parameter
  16. var parseJSON: (JSON) -> Content?
  17. init(host: String = "https://api.pai.ai",
  18. path: Interfaces, parameter: Parameter,
  19. parseJSON: @escaping (JSON) -> Content?) {
  20. self.host = host
  21. self.path = path
  22. self.parameter = parameter
  23. self.parseJSON = parseJSON
  24. }
  25. func parse(_ json: JSON) -> Content? {
  26. return parseJSON(json)
  27. }
  28. func loadContent() -> Single<Content> {
  29. return NetworkApi.share.post(resource: self)
  30. }
  31. }