Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@ end_of_line = lf
insert_final_newline = true
trim_trailing_whitespace = true

[*.{kt,gradle}]
[*.{kt,kts}]
indent_style = space
indent_size = 4
ktlint_standard_no-wildcard-imports = disabled
ktlint_standard_filename = disabled
ktlint_standard_enum-entry-name-case = disabled
83 changes: 0 additions & 83 deletions kotlin/build.gradle

This file was deleted.

65 changes: 65 additions & 0 deletions kotlin/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
group = "com.looker.sdk"
defaultTasks = mutableListOf("jar")

val kotlinVersion = providers.gradleProperty("kotlinVersion").get()
val ktorVersion = providers.gradleProperty("ktorVersion").get()

plugins {
kotlin("jvm")
id("com.diffplug.spotless")
}

sourceSets {
main {
kotlin {
setSrcDirs(listOf("src/main/"))
}
}
test {
kotlin {
setSrcDirs(listOf("src/test"))
}
}
}

repositories {
mavenCentral()
maven { url = uri("https://dl.bintray.com/kotlin/ktor") }
maven { url = uri("https://dl.bintray.com/kotlin/kotlinx") }
maven { url = uri("https://jitpack.io") }
}

dependencies {
implementation("org.jetbrains.kotlin:kotlin-reflect:$kotlinVersion")

implementation("io.github.cdimascio:dotenv-kotlin:6.2.2")
implementation("org.ini4j:ini4j:0.5.4")

implementation("io.ktor:ktor-client:$ktorVersion")
implementation("io.ktor:ktor-client-okhttp:$ktorVersion")
implementation("io.ktor:ktor-client-json:$ktorVersion")
implementation("io.ktor:ktor-client-gson:$ktorVersion")

implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.6.4")
implementation("com.google.code.gson:gson:2.8.5")

testImplementation("org.junit.jupiter:junit-jupiter-api:5.3.1")
testRuntimeOnly("org.junit.jupiter:junit-jupiter-engine:5.3.1")
testImplementation("org.jetbrains.kotlin:kotlin-test-junit:$kotlinVersion")
}

spotless {
kotlin {
ktlint("0.50.0").setEditorConfigPath("$projectDir/../.editorconfig")
}
}

kotlin {
jvmToolchain(17)
}

tasks.test {
testLogging {
exceptionFormat = org.gradle.api.tasks.testing.logging.TestExceptionFormat.FULL
}
}
2 changes: 1 addition & 1 deletion kotlin/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
kotlinVersion=1.7.10
kotlinVersion=1.9.10
ktorVersion=1.5.4
2 changes: 1 addition & 1 deletion kotlin/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.7.1-bin.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-8.3-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
7 changes: 0 additions & 7 deletions kotlin/settings.gradle

This file was deleted.

10 changes: 10 additions & 0 deletions kotlin/settings.gradle.kts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
rootProject.name = "looker-kotlin-sdk"

pluginManagement {
val kotlinVersion = providers.gradleProperty("kotlinVersion").get()
plugins {
kotlin("jvm") version kotlinVersion
id("com.diffplug.spotless") version "6.20.0"
id("org.gradle.toolchains.foojay-resolver-convention") version "0.7.0"
}
}
10 changes: 5 additions & 5 deletions kotlin/src/main/com/looker/rtl/AuthSession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ import io.ktor.http.*

open class AuthSession(
open val apiSettings: ConfigurationProvider,
open val transport: Transport = Transport(apiSettings)
open val transport: Transport = Transport(apiSettings),
) {

var authToken: AuthToken = AuthToken()
Expand Down Expand Up @@ -148,15 +148,15 @@ open class AuthSession(
Parameters.build {
append(client_id, clientId)
append(client_secret, clientSecret)
}
},
)
val token = ok<AuthToken>(
transport.request<AuthToken>(
HttpMethod.POST,
"$apiPath/login",
emptyMap(),
body
)
body,
),
)
authToken = token
}
Expand All @@ -165,7 +165,7 @@ open class AuthSession(
val token = activeToken()
val sudoToken = transport.request<AuthToken>(
HttpMethod.POST,
"/login/$newId"
"/login/$newId",
) { requestSettings ->
val headers = requestSettings.headers.toMutableMap()
if (token.accessToken.isNotBlank()) {
Expand Down
4 changes: 2 additions & 2 deletions kotlin/src/main/com/looker/rtl/AuthToken.kt
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ data class AuthToken(
@SerializedName("expires_in")
var expiresIn: Long = 0L,
@SerializedName("refresh_token")
var refreshToken: String? = null
var refreshToken: String? = null,
) {

var expiresAt: LocalDateTime = LocalDateTime.now()
Expand All @@ -53,7 +53,7 @@ data class AuthToken(
token.access_token!!,
token.token_type!!,
token.expires_in!!.toLong(),
token.refresh_token
token.refresh_token,
)

init {
Expand Down
2 changes: 1 addition & 1 deletion kotlin/src/main/com/looker/rtl/Constants.kt
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ fun unQuote(value: String?): String {
enum class ResponseMode {
String,
Binary,
Unknown
Unknown,
}

fun responseMode(contentType: String): ResponseMode {
Expand Down
22 changes: 14 additions & 8 deletions kotlin/src/main/com/looker/rtl/ErrorDoc.kt
Original file line number Diff line number Diff line change
Expand Up @@ -30,18 +30,21 @@ class ErrorDocItem(var url: String)
/** Structure of the error code document index */
typealias ErrorCodeIndex = HashMap<String, ErrorDocItem>

interface IErrorDocLink {
interface IErrorDocLink {
/** base redirector url */
var redirector: String

/** api version of the error link */
var apiVersion: String

/** HTTP status code */
var statusCode: String

/** REST API Path */
var apiPath: String
}
}

interface IErrorDoc {
interface IErrorDoc {
/** Index of all known error codes. Call load() to populate it */
var index: ErrorCodeIndex?

Expand Down Expand Up @@ -103,10 +106,10 @@ typealias ErrorCodeIndex = HashMap<String, ErrorDocItem>
* @param errorMdUrl url for the error document
*/
fun methodName(errorMdUrl: String): String
}
}

/** Class to process Looker API error payloads and retrieve error documentation */
class ErrorDoc(val sdk: APIMethods, val cdnUrl: String = ErrorCodesUrl): IErrorDoc {
class ErrorDoc(val sdk: APIMethods, val cdnUrl: String = ErrorCodesUrl) : IErrorDoc {
companion object {
/** Location of the public CDN for Looker API Error codes */
const val ErrorCodesUrl = "https://static-a.cdn.looker.app/errorcodes/"
Expand Down Expand Up @@ -143,7 +146,7 @@ class ErrorDoc(val sdk: APIMethods, val cdnUrl: String = ErrorCodesUrl): IErrorD
match.groupValues[1],
match.groupValues[2],
match.groupValues[3],
match.groupValues[4]
match.groupValues[4],
)
}

Expand Down Expand Up @@ -182,7 +185,10 @@ class ErrorDoc(val sdk: APIMethods, val cdnUrl: String = ErrorCodesUrl): IErrorD

override fun specPath(path: String): String {
val rx = Regex("""(:\w+)""")
val result = path.replace(rx) { val x = it.value.substring(1); "{$x}" }
val result = path.replace(rx) {
val x = it.value.substring(1)
"{$x}"
}
return result
}

Expand Down Expand Up @@ -220,5 +226,5 @@ class ErrorDocLink(
override var redirector: String = "",
override var apiVersion: String = "",
override var statusCode: String = "",
override var apiPath: String = ""
override var apiPath: String = "",
) : IErrorDocLink
14 changes: 7 additions & 7 deletions kotlin/src/main/com/looker/rtl/OAuthSession.kt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ fun base64UrlEncode(bytes: ByteArray): String {
@ExperimentalUnsignedTypes
class OAuthSession(
override val apiSettings: ConfigurationProvider,
override val transport: Transport = Transport(apiSettings)
override val transport: Transport = Transport(apiSettings),
) :
AuthSession(apiSettings, transport) {
private var random = SecureRandom()
Expand All @@ -52,7 +52,7 @@ class OAuthSession(
HttpMethod.POST,
"/api/token",
emptyMap(),
body
body,
)
val token = this.ok<AccessToken>(response)
this.authToken.setToken(token)
Expand All @@ -69,8 +69,8 @@ class OAuthSession(
"grant_type" to "refresh_token",
"refresh_token" to this.activeToken().refreshToken,
"client_id" to config["client_id"],
"redirect_uri" to config["redirect_uri"]
)
"redirect_uri" to config["redirect_uri"],
),
)
}
}
Expand All @@ -94,8 +94,8 @@ class OAuthSession(
"scope" to scope,
"state" to state,
"code_challenge_method" to "S256",
"code_challenge" to codeChallenge
)
"code_challenge" to codeChallenge,
),
)
}

Expand All @@ -107,7 +107,7 @@ class OAuthSession(
"code" to authCode,
"code_verifier" to verifier,
"client_id" to (config["client_id"] ?: error("")),
"redirect_uri" to (config["redirect_uri"] ?: error(""))
"redirect_uri" to (config["redirect_uri"] ?: error("")),
)
}

Expand Down
Loading