Added check for valid API token.

This commit is contained in:
Erik C. Thauvin 2020-06-09 14:06:40 -07:00
parent 2485f898de
commit e2cb9e2954
7 changed files with 25 additions and 14 deletions

View file

@ -6,12 +6,16 @@ public final class BitlySample {
public static void main(final String[] args) {
if (args.length > 0) {
final Bitly bitly = new Bitly(/* "YOUR_API_TOKEN from https://bitly.is/accesstoken" */);
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));
if (!bitly.getAccessToken().isEmpty()) {
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("Please specify a Bitly API access token.");
}
} else {
System.err.println("Try specifying one or more URLs as arguments.");

View file

@ -6,11 +6,15 @@ import kotlin.system.exitProcess
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))
if (bitly.accessToken.isNotEmpty()) {
args.forEach {
if (it.contains("bit.ly"))
println(it + " <-- " + bitly.bitlinks().expand(it))
else
println(it + " --> " + bitly.bitlinks().shorten(it))
}
} else {
println("Please specify a Bitly API access token.")
}
} else {
println("Try specifying one or more URLs as arguments.")