From 4df80fe88fc435aaf1f20375e783adfeee73c767 Mon Sep 17 00:00:00 2001 From: nathan Date: Sun, 28 Jul 2019 15:00:22 +0200 Subject: [PATCH] code cleanup, moved test classes to test dir --- build.gradle.kts | 58 +++++++--------- src/dorkbox/api/dns/UpdateDnsRecord.kt | 8 --- test/dorkbox/kloudflare/KloudflareTest.kt | 82 +++++++++++++++++++++++ 3 files changed, 108 insertions(+), 40 deletions(-) delete mode 100644 src/dorkbox/api/dns/UpdateDnsRecord.kt create mode 100644 test/dorkbox/kloudflare/KloudflareTest.kt diff --git a/build.gradle.kts b/build.gradle.kts index e40ed96..6f52690 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -10,7 +10,7 @@ plugins { id("com.dorkbox.VersionUpdate") version "1.4.1" id("com.dorkbox.GradleUtils") version "1.2" - kotlin("jvm") version "1.3.31" + kotlin("jvm") version "1.3.40" } object Extras { @@ -55,6 +55,15 @@ sourceSets { include("**/*.java", "**/*.kt") } } + + test { + java { + setSrcDirs(listOf("test")) + + // want to include java and kotlin files for the source. 'setSrcDirs' resets includes... + include("**/*.java", "**/*.kt") + } + } } repositories { @@ -102,6 +111,9 @@ configurations.all { // e.g. multiple different versions of the same dependency (group and name are equal) failOnVersionConflict() + // if there is a version we specified, USE THAT VERSION (over transitive versions) + preferProjectModules() + // cache dynamic versions for 10 minutes cacheDynamicVersionsFor(10 * 60, "seconds") @@ -117,50 +129,32 @@ dependencies { implementation("org.jetbrains.kotlin:kotlin-stdlib-common") implementation("org.jetbrains.kotlin:kotlin-reflect") - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.2.1") { - isTransitive = false - } - implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:1.2.1") { - isTransitive = false - } + val coroutrineVer = "1.2.2" + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:$coroutrineVer") + implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core-common:$coroutrineVer") - val okHttpVer = "3.14.2" + val okHttpVer = "4.0.0" val moshiVer = "1.8.0" + val retroVer = "2.6.0" implementation("com.squareup.okhttp3:okhttp:$okHttpVer") - - // Log Network Calls - implementation("com.squareup.okhttp3:logging-interceptor:3.14.2") + implementation("com.squareup.okhttp3:logging-interceptor:$okHttpVer") // Log Network Calls // For serialization. THESE ARE NOT TRANSITIVE because it screws up the kotlin version - implementation("com.squareup.retrofit2:retrofit:2.5.0") { - isTransitive = false - } - implementation("com.squareup.retrofit2:converter-moshi:2.5.0") { - isTransitive = false - } - implementation ("com.squareup.moshi:moshi:$moshiVer") { - isTransitive = false - } - implementation ("com.squareup.moshi:moshi-kotlin:$moshiVer") { - isTransitive = false - } + implementation("com.squareup.retrofit2:retrofit:$retroVer") + implementation("com.squareup.retrofit2:converter-moshi:$retroVer") + implementation ("com.squareup.moshi:moshi:$moshiVer") + implementation ("com.squareup.moshi:moshi-kotlin:$moshiVer") // awesome logging framework for kotlin. // https://www.reddit.com/r/Kotlin/comments/8gbiul/slf4j_loggers_in_3_ways/ // https://github.com/MicroUtils/kotlin-logging - implementation("io.github.microutils:kotlin-logging:1.6.26") { - isTransitive = false - } - implementation("io.github.microutils:kotlin-logging-common:1.6.26") { - isTransitive = false - } + implementation("io.github.microutils:kotlin-logging:1.6.26") + implementation("io.github.microutils:kotlin-logging-common:1.6.26") implementation("org.slf4j:slf4j-api:1.7.26") implementation("ch.qos.logback:logback-core:1.2.3") - implementation("ch.qos.logback:logback-classic:1.2.3") { - isTransitive = false - } + implementation("ch.qos.logback:logback-classic:1.2.3") } diff --git a/src/dorkbox/api/dns/UpdateDnsRecord.kt b/src/dorkbox/api/dns/UpdateDnsRecord.kt deleted file mode 100644 index cece9fe..0000000 --- a/src/dorkbox/api/dns/UpdateDnsRecord.kt +++ /dev/null @@ -1,8 +0,0 @@ -package dorkbox.api.dns - -/** - * https://api.cloudflare.com/#dns-records-for-a-zone-update-dns-record - * - * This is the "same" object as creating a new record. This is a different type in order to prevent confusion and simplify naming conventions - */ -class UpdateDnsRecord(dnsRecord: DnsRecord) : CreateDnsRecord(dnsRecord) diff --git a/test/dorkbox/kloudflare/KloudflareTest.kt b/test/dorkbox/kloudflare/KloudflareTest.kt new file mode 100644 index 0000000..1aa89e2 --- /dev/null +++ b/test/dorkbox/kloudflare/KloudflareTest.kt @@ -0,0 +1,82 @@ +package dorkbox.kloudflare + +import org.slf4j.Logger +import org.slf4j.LoggerFactory +import java.time.Instant +import java.util.* + +/** + * + */ +object KloudflareTest { + private val logger: Logger + + init { + // fix logging context + val property = System.getProperty("logging.context") + if (property == null) { + // we also have "webserver", but that is specified during webserver production launch + System.setProperty("logging.context", "kloudflareAPI") + } + + logger = LoggerFactory.getLogger(Kloudflare::class.java) + Thread.setDefaultUncaughtExceptionHandler { t, e -> logger.error("Uncaught exception in thread: '{}'", t.name, e) } + } + + @JvmStatic + fun main(arguments: Array) { + // drop everything to lower case. + for ((index, value) in arguments.withIndex()) { + val lowerCase = value.toLowerCase(Locale.US) + arguments[index] = lowerCase + } + + logger.info("Starting : {} ", Instant.now().toString()) + + // start up the application! + val jvmName = System.getProperty("java.vm.name") + val jvmVersion = System.getProperty("java.version") + val jvmVendor = System.getProperty("java.vm.specification.vendor") + logger.info("Execution JVM: $jvmVendor $jvmName $jvmVersion") + logger.info("Execution arguments: ${arguments.joinToString()}") + + + val email = "user@example.com" + val token = "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" + + val kloudflare = Kloudflare(email, token) + + println(kloudflare.getUserDetails()) + println(kloudflare.getUserBillingProfile()) + println(kloudflare.getUserBillingHistory()) + + + val zones = kloudflare.listZones() + +// println(kloudflare.getZoneRatePlans("123")) +// println(kloudflare.getZoneRatePlans("123")) +// println(kloudflare.getZoneSettings("123")) +// println(kloudflare.listDnsRecords("123")) +// println(kloudflare.listAccessRules()) + + + +// val history = cloudflare.getUserBillingHistory(email, token).execute() +// println("user: ${history.body()?.result}") +// +// val zones = cloudflare.listZones(email, token).execute().body()?.result +// println("user: ${zones.body()?.result}") + +// val zoneRatePlans = cloudflare.getZoneRatePlans(email, token, "123").execute() +// println("user: ${zoneRatePlans.body()?.result}") +// +// val zoneSettings = cloudflare.getZoneSettings(email, token, "123").execute() +// println("user: ${zoneSettings.body()?.result}") +// +// val dnsRecords = cloudflare.listDnsRecords(email, token, "123").execute() +// println("user: ${dnsRecords.body()?.result}") + + + kloudflare.shutdown() + } +}