Advertisement
alestro

Moya RxSwift Example

Apr 8th, 2016
147
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Swift 1.25 KB | None | 0 0
  1. final class PVProductListService {
  2.    
  3.     class func productListWithId(campaignId: String, categoryId: String) -> Observable < PVProductList > {
  4.         return networkStubbedProvider
  5.             .request(.ProductsList(campaignId, categoryId))
  6.             .pvValidateResponse()
  7.             .pvMapObject(PVProductList)
  8.     }
  9. }  
  10.  
  11. import ObjectMapper
  12.  
  13. final class PVProductList: PVModel {
  14.     var campaignId: String?
  15.     var categoryId: String?
  16.     var campaignName: String?
  17.     var categoryName: String?
  18.     var products: [PVProduct]?
  19.    
  20.     override func mapping(map: Map) {
  21.         campaignId <- map["data.campaign_data.campaign_PK"]
  22.         categoryId <- map["data.category_data.category_PK"]
  23.         campaignName <- map["data.campaign_data.campaign_name"]
  24.         categoryName <- map["data.category_data.category_name"]
  25.         products <- map["data.products"]
  26.        
  27.         super.mapping(map)
  28.     }
  29. }
  30.  
  31. //MARK: - Response validation
  32. extension ObservableType where E == Response {
  33.    
  34.     @warn_unused_result
  35.     func pvValidateResponse() -> Observable<PVJSON> {
  36.         return self.filterSuccessfulStatusAndRedirectCodes()
  37.             .mapJSON()
  38.             .pvValidateJSON()
  39.             .pvFilterSuccessfulDataStatuses()
  40.     }
  41.    
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement