-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCaterogyModel.swift
35 lines (29 loc) · 1000 Bytes
/
CaterogyModel.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
//
// CaterogyModel.swift
// Gank
//
// Created by 魏星 on 16/7/27.
// Copyright © 2016年 wx. All rights reserved.
//
import Foundation
import RxSwift
import ObjectMapper
class CategoryModel: BaseModel<MeiPaiApi>{
var caterories: [CategoryEntity]?
override init() {
caterories = []
super.init()
}
func getCategories() -> Observable<[CategoryEntity]> {
return requestProvider.request(MeiPaiApi.GetCategoryList).filterStatusCodes(200...201)
.observeOn(backgroundScheduler).map { (response) -> [CategoryEntity]in
if let result = Mapper<CategoryEntity>().mapArray(String(data: response.data, encoding: NSUTF8StringEncoding)){
return result
}else{
throw NSError(domain: "parse json error", code: -1, userInfo: ["json": response])
}
}.doOnNext({ (entities) in
self.caterories = entities
}).observeOn(MainScheduler.instance)
}
}