This lib provides basic functions for building kotlin scripts using kscript tool. These are:
- http.kt - functions for handling http requests (request, header, get, post, put, patch...)
- db.kt - helper functions for db connection establishment and generic select query
- auth.kt - core authentication request and api key parsing
- log.kt - basic log functions (info, error, success)
This library is not released yet.
Use current SNAPSHOT version.
This library is not released yet.
Use current SNAPSHOT version.
#!/usr/bin/env kscript
@file:CompilerOpts("-jvm-target 1.8")
@file:DependsOn("cz.my2n.libs:kscript-lib:$libVersion")
try {
val credentials = Credentials("[email protected]", "secretPassword")
val baseUrl = "https://my2n-testprod.dev.2n.cz/middleware/api/partner/v1"
val apiKey: ApiKey = authenticate(baseUrl, credentials)
val accessToken = header("x-api-key")(apiKey.accessToken)
val devices = parseResponse(call(get(baseUrl, "/devices", accessToken)))
} catch(e: Exception) {
error(e.message)
}
info("Done.")
#!/usr/bin/env kscript
@file:CompilerOpts("-jvm-target 1.8")
@file:DependsOn("cz.my2n.libs:kscript-lib:$libVersion")
try {
val connection: Connection? = createConnection(mvsConnString)
connection?.let {
val queryParams: Map<String, String> = mapOf("sipNumber", "123456")
val rowToDevice: (Row) -> Device = { Device(it.id, it.sipNumber) }
val devices: Set<Device> = select("select * from device where sip_number = :sipNumber", queryParams, connection, rowToDevice)
// ...
}
} catch(e: Exception) {
error(e.message)
}
info("Done.")