Skip to content

Instantly share code, notes, and snippets.

@yota345
Last active September 25, 2016 16:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save yota345/161420cbd38c5da9f563f7be2975cc3d to your computer and use it in GitHub Desktop.
Save yota345/161420cbd38c5da9f563f7be2975cc3d to your computer and use it in GitHub Desktop.
/**
Eventモデル
- requestState: API通信の状態を扱う
- disposeBag: RxSwiftで不要なstreamを削除するためのクラス
*/
struct EventsModel {
internal let requestState = Variable(RequestState.Stopped)
private let disposeBag = DisposeBag()
}
extension EventsModel {
/**
- Eventの一覧を取得する
- APIレスポンスは、self.requestStateに格納
*/
func fetchEventList(count: Int) {
requestState.value = .Requesting
EventsRequest
.GetEvents(count)
.request()
.map{ try! decodeValue($0) as EventListResponse }
.subscribe(
onNext: {
self.requestState.value = .Response($0)
}, onError: {
self.requestState.value = .Error($0)
}
)
.addDisposableTo(disposeBag)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment