This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import RxSwift | |
import Himotoki | |
/** | |
API通信の状態を表現 | |
- .Stopped: API通信をまだ行っていない状態 | |
- .Requesting: API通信中 | |
- .Error(ErrorType): API通信でエラーが返ってきた状態 | |
- .Response(Decodable?): API通信でencode済みレスポンスを受け取っている |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Himotoki | |
/** | |
Event一覧を取得した後のJSONエンコードを設定 | |
*/ | |
struct EventListResponse: Decodable { | |
internal let results_returned: Int | |
internal let results_start: String | |
internal let events: [Events] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Eventモデル | |
- requestState: API通信の状態を扱う | |
- disposeBag: RxSwiftで不要なstreamを削除するためのクラス | |
*/ | |
struct EventsModel { | |
internal let requestState = Variable(RequestState.Stopped) | |
private let disposeBag = DisposeBag() | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
EventsRequest | |
.GetEvents(count) | |
.request() | |
.subscribe( | |
onNext: { | |
print("API response: \($0)") | |
}, onError: { | |
print("Error: \($0)") | |
} | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import Alamofire | |
import RxSwift | |
/** | |
API通信をするためのプロトコル | |
- parameters: パラメーターを指定 | |
- baseURL: APIのドメインを指定 | |
- path: APIのパスを指定 | |
- method: CRUDを指定 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# HTTP通信用ライブラリ | |
github "Alamofire/Alamofire" | |
# RxSwift | |
github "ReactiveX/RxSwift" | |
# JSON parser | |
github "ikesyo/Himotoki" |
NewerOlder