Implemented examples.

This commit is contained in:
Erik C. Thauvin 2020-02-27 00:38:37 -08:00
parent 42348476f6
commit 5c64d4b30e
3 changed files with 26 additions and 6 deletions

View file

@ -4,9 +4,8 @@ plugins {
application
}
// ./gradlew run runJava
defaultTasks(ApplicationPlugin.TASK_RUN_NAME)
// ./gradlew run --args='https://erik.thauvin.net'
// ./gradlew runJava --args='https://erik.thauvin.net'
repositories {
mavenLocal()

View file

@ -4,7 +4,18 @@ import net.thauvin.erik.bitly.Bitly;
public class BitlySample {
public static void main(String[] args) {
System.out.println(new Bitly("YOUR_API_KEY").bitlinks().shorten("https://erik.thauvin.net/blog"));
final Bitly bitly = new Bitly(/* "YOUR_API_TOKEN from https://bitly.is/accesstoken" */);
if (args.length > 0) {
for (final String arg : args) {
if (arg.contains("bit.ly")) {
System.out.println(arg + " <-- " + bitly.bitlinks().expand(arg));
} else {
System.out.println(arg + " --> " + bitly.bitlinks().shorten(arg));
}
}
} else {
System.err.println("Try specifying one or more URLs as arguments.");
}
System.exit(0);
}
}

View file

@ -3,7 +3,17 @@ package com.example
import net.thauvin.erik.bitly.Bitly
import kotlin.system.exitProcess
fun main() {
println(Bitly("YOUR_API_KEY").bitlinks().shorten("https://erik.thauvin.net/blog"))
fun main(args: Array<String>) {
if (args.isNotEmpty()) {
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))
else
println(it + " --> " + bitly.bitlinks().shorten(it))
}
} else {
println("Try specifying one or more URLs as arguments.")
}
exitProcess(0)
}