Skip to content

Commit 2cefbdc

Browse files
committed
task: update readme
1 parent b5746e2 commit 2cefbdc

File tree

1 file changed

+31
-7
lines changed

1 file changed

+31
-7
lines changed

README.md

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,24 @@ Config.environment = Environment.PRODUCTION // For production
4444
Interaction with the APIs is done via the `Api` singleton. The Api singleton provides access to a configured Ktor client for interaction with the Api. A session token can also be applied:
4545

4646
```kotlin
47-
Api.sessionToken = "valid_session_token"
47+
Api.applySessionToken("valid_session_token")
48+
```
49+
50+
### Applying Ktor config
51+
Ktor configuration can be applied using the `Api.withHttpClientConfig` method:
52+
53+
```kotlin
54+
Api.withHttpClientConfig {
55+
install(Logging) {
56+
level = LogLevel.ALL
57+
}
58+
}
4859
```
4960

5061
### Routers
51-
Routers are used to encapsulate specific areas of the API. For example, the `VehiclesRouter` takes care of all Vehicle API interactions. Routers are attached to the `Api` object via extension properties.
62+
Routers are used to encapsulate specific areas of the API. For example, the `VehiclesRouter` takes care of all Vehicle API interactions. Routers are attached to the `Api` object via extension properties.
63+
64+
For more information: https://ktor.io/docs/client-logging.html
5265

5366
#### Example usage of the `VehiclesRouter`:
5467

@@ -64,11 +77,22 @@ val response: List<Vehicle> = api.vehicles.all("organisation-id", VehicleRequest
6477
## Examples of Usage
6578

6679
```kotlin
67-
Config.environment = Environment.STAGING
68-
Api.sessionToken = "" // Replace with an actual session token
69-
7080
runBlocking {
71-
val response = Api.vehicles.all("123")
72-
println(response.size)
81+
Config.environment = Environment.STAGING
82+
val authResponse = Api.auth.initiate()
83+
Api.withHttpClientConfig {
84+
install(Logging) {
85+
level = LogLevel.ALL
86+
}
87+
}
88+
89+
val response = Api.auth.complete(authResponse.id, payload = LoginPayload(
90+
identifier = "[email protected]",
91+
password = "Password1!",
92+
))
93+
94+
Api.applySessionToken(response.sessionToken)
95+
val vehicles = Api.vehicles.all("org-123")
96+
println(vehicles.size)
7397
}
7498
```

0 commit comments

Comments
 (0)