From b31b21d481afca958291ec5839f925b507bc4165 Mon Sep 17 00:00:00 2001 From: "Erik C. Thauvin" Date: Sun, 1 Mar 2020 20:41:33 -0800 Subject: [PATCH] Cleaned up and added retrieve example. --- examples/build.gradle.kts | 1 + .../main/kotlin/com/example/BitlyExample.kt | 2 +- .../main/kotlin/com/example/BitlyRetrieve.kt | 19 +++++++++++++++++++ 3 files changed, 21 insertions(+), 1 deletion(-) create mode 100644 examples/src/main/kotlin/com/example/BitlyRetrieve.kt diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index a09eabb..33e30b1 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -15,6 +15,7 @@ repositories { dependencies { implementation(platform("org.jetbrains.kotlin:kotlin-bom")) implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") + implementation("org.json:json:20190722") implementation("net.thauvin.erik:bitly-shorten:0.9.0-beta") } diff --git a/examples/src/main/kotlin/com/example/BitlyExample.kt b/examples/src/main/kotlin/com/example/BitlyExample.kt index afe6c92..208758a 100644 --- a/examples/src/main/kotlin/com/example/BitlyExample.kt +++ b/examples/src/main/kotlin/com/example/BitlyExample.kt @@ -5,7 +5,7 @@ import kotlin.system.exitProcess fun main(args: Array) { if (args.isNotEmpty()) { - val bitly = Bitly(/* "YOUR_API_ACCESS_TOKEN from https://bitly.is/accesstoken" */) // + val bitly = Bitly(/* "YOUR_API_ACCESS_TOKEN from https://bitly.is/accesstoken" */) args.forEach { if (it.contains("bit.ly")) println(it + " <-- " + bitly.bitlinks().expand(it)) diff --git a/examples/src/main/kotlin/com/example/BitlyRetrieve.kt b/examples/src/main/kotlin/com/example/BitlyRetrieve.kt new file mode 100644 index 0000000..ced18d8 --- /dev/null +++ b/examples/src/main/kotlin/com/example/BitlyRetrieve.kt @@ -0,0 +1,19 @@ +package com.example + +import net.thauvin.erik.bitly.Bitly +import net.thauvin.erik.bitly.Methods +import net.thauvin.erik.bitly.Utils.Companion.toEndPoint +import org.json.JSONObject +import kotlin.system.exitProcess + +fun main() { + val bitly = Bitly(/* "YOUR_API_ACCESS_TOKEN from https://bitly.is/accesstoken" */) + + val json = JSONObject(bitly.call("/bitlinks/bit.ly/380ojFd".toEndPoint(), method = Methods.GET)) + + println("Bitlink is titled : " + json.getString("title")) + println("Bitlink created by: " + json.getString("created_by")) + + exitProcess(0) +} +