@@ -11,17 +11,67 @@ A Kotlin library containing a parser and models for the Engelsystem:
1111
1212## Usage
1313
14+ The library is published as two separate artifacts: ` engelsystem-base ` and ` engelsystem-repositories ` .
15+ You can use either of them depending on your needs.
16+
17+ #### Usage of ` engelsystem-base `
18+
19+ The ` engelsystem-base ` artifact returns a ` Response<List<Shift>> ` type from the suspending
20+ ` EngelsystemService#getShifts() ` function.
21+
1422``` kotlin
15- val engelsystemApi: EngelsystemApi = Api
16- engelsystemApi.provideEngelsystemService(BASE_URL , okHttpClient)
17- .getShifts(
18- eTag = " " , // Pass an empty string or a previous ETag value for caching
19- lastModifiedAt = " " , // Pass an empty string or a previous Last-Modified value for caching
20- path = URL_PART_PATH ,
21- apiKey = API_KEY ,
22- )
23+ val api: EngelsystemApi = Api
24+ val service: EngelsystemService = api.provideEngelsystemService(BASE_URL , okHttpClient)
25+ service.getShifts(
26+ eTag = " " , // Pass an empty string or a previous ETag value for caching
27+ lastModifiedAt = " " , // Pass an empty string or a previous Last-Modified value for caching
28+ path = URL_PART_PATH ,
29+ apiKey = API_KEY ,
30+ )
31+ if (response.isSuccessful) {
32+ val shifts = response.body()
33+ val responseETag = response.headers()[" ETag" ]
34+ val responseLastModifiedAt = response.headers()[" Last-Modified" ]
35+ } else {
36+ val errorCode = response.code()
37+ val errorMessage = response.message()
38+ }
2339```
2440
41+ The ` engelsystem-repositories ` artifact returns a ` Flow<GetShiftsState> ` type from the suspending
42+ ` SimpleEngelsystemRepository#getShiftsState() ` function.
43+
44+ ``` kotlin
45+ val api: EngelsystemApi = Api
46+ val repository = SimpleEngelsystemRepository (
47+ callFactory = OkHttpClient .Builder ().build(),
48+ api = api,
49+ )
50+
51+ repository.getShiftsState(
52+ requestETag = " " , // Pass an empty string or a previous ETag value for caching
53+ requestLastModifiedAt = " " , // Pass an empty string or a previous Last-Modified value for caching
54+ baseUrl = BASE_URL ,
55+ path = URL_PART_PATH ,
56+ apiKey = API_KEY ,
57+ )
58+ .collectLatest { state: GetShiftsState ->
59+ when (state) {
60+ is Success -> {
61+ val shifts = state.shifts
62+ val responseETag = state.responseETag
63+ val responseLastModifiedAt = state.responseLastModifiedAt
64+ }
65+ is Error -> {
66+ val httpStatusCode = state.httpStatusCode
67+ val errorMessage = state.errorMessage
68+ }
69+ is Failure -> {
70+ val throwable = state.throwable
71+ }
72+ }
73+ }
74+ ```
2575
2676### Time stamps
2777
@@ -48,12 +98,13 @@ allprojects {
4898}
4999```
50100
51- and to your application module ` build.gradle ` :
101+ and one of the following dependencies to your application module ` build.gradle ` :
52102
53103
54104``` groovy
55105dependencies {
56106 implementation "info.metadude.kotlin.library.engelsystem:engelsystem-base:$version"
107+ implementation "info.metadude.kotlin.library.engelsystem:engelsystem-repositories:$version"
57108}
58109```
59110
0 commit comments