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

@ -1,5 +1,5 @@
plugins { plugins {
id("org.jetbrains.kotlin.jvm") version "1.3.71" id("org.jetbrains.kotlin.jvm") version "1.3.72"
id("com.github.ben-manes.versions") version "0.28.0" id("com.github.ben-manes.versions") version "0.28.0"
application application
} }
@ -18,8 +18,8 @@ dependencies {
implementation(platform("org.jetbrains.kotlin:kotlin-bom")) implementation(platform("org.jetbrains.kotlin:kotlin-bom"))
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
implementation("net.thauvin.erik:bitly-shorten:0.9.1-beta") implementation("net.thauvin.erik:bitly-shorten:0.9.2")
implementation("org.json:json:20190722") implementation("org.json:json:20200518")
} }
application { application {

Binary file not shown.

View file

@ -1,5 +1,5 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.2.2-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists zipStorePath=wrapper/dists

2
examples/gradlew vendored
View file

@ -82,6 +82,7 @@ esac
CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar CLASSPATH=$APP_HOME/gradle/wrapper/gradle-wrapper.jar
# Determine the Java command to use to start the JVM. # Determine the Java command to use to start the JVM.
if [ -n "$JAVA_HOME" ] ; then if [ -n "$JAVA_HOME" ] ; then
if [ -x "$JAVA_HOME/jre/sh/java" ] ; then if [ -x "$JAVA_HOME/jre/sh/java" ] ; then
@ -129,6 +130,7 @@ fi
if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then
APP_HOME=`cygpath --path --mixed "$APP_HOME"` APP_HOME=`cygpath --path --mixed "$APP_HOME"`
CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"`
JAVACMD=`cygpath --unix "$JAVACMD"` JAVACMD=`cygpath --unix "$JAVACMD"`
# We build the pattern for arguments to be converted via cygpath # We build the pattern for arguments to be converted via cygpath

View file

@ -84,6 +84,7 @@ set CMD_LINE_ARGS=%*
set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar
@rem Execute Gradle @rem Execute Gradle
"%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS% "%JAVA_EXE%" %DEFAULT_JVM_OPTS% %JAVA_OPTS% %GRADLE_OPTS% "-Dorg.gradle.appname=%APP_BASE_NAME%" -classpath "%CLASSPATH%" org.gradle.wrapper.GradleWrapperMain %CMD_LINE_ARGS%

View file

@ -6,6 +6,7 @@ public final class BitlySample {
public static void main(final String[] args) { public static void main(final String[] args) {
if (args.length > 0) { if (args.length > 0) {
final Bitly bitly = new Bitly(/* "YOUR_API_TOKEN from https://bitly.is/accesstoken" */); final Bitly bitly = new Bitly(/* "YOUR_API_TOKEN from https://bitly.is/accesstoken" */);
if (!bitly.getAccessToken().isEmpty()) {
for (final String arg : args) { for (final String arg : args) {
if (arg.contains("bit.ly")) { if (arg.contains("bit.ly")) {
System.out.println(arg + " <-- " + bitly.bitlinks().expand(arg)); System.out.println(arg + " <-- " + bitly.bitlinks().expand(arg));
@ -13,6 +14,9 @@ public final class BitlySample {
System.out.println(arg + " --> " + bitly.bitlinks().shorten(arg)); System.out.println(arg + " --> " + bitly.bitlinks().shorten(arg));
} }
} }
} else {
System.err.println("Please specify a Bitly API access token.");
}
} else { } else {
System.err.println("Try specifying one or more URLs as arguments."); System.err.println("Try specifying one or more URLs as arguments.");
} }

View file

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