diff --git a/README.md b/README.md index bfb039b..95d243d 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ [![Known Vulnerabilities](https://snyk.io/test/github/ethauvin/bitly-shorten/badge.svg?targetFile=pom.xml)](https://snyk.io/test/github/ethauvin/bitly-shorten?targetFile=pom.xml) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=ethauvin_bitly-shorten&metric=alert_status)](https://sonarcloud.io/dashboard?id=ethauvin_bitly-shorten) [![Build Status](https://travis-ci.com/ethauvin/bitly-shorten.svg?branch=master)](https://travis-ci.com/ethauvin/bitly-shorten) [![CircleCI](https://circleci.com/gh/ethauvin/bitly-shorten/tree/master.svg?style=shield)](https://circleci.com/gh/ethauvin/bitly-shorten/tree/master) -# [Bitly](https://dev.bitly.com/v4/) Shortener for Kotlin/Java +# [Bitly](https://dev.bitly.com/v4/) Shortener for Kotlin/Java/Android A simple implementation of the link shortening ([bitlinks](https://dev.bitly.com/v4/#tag/Bitlinks)) abilities of the [Bitly v4 API](https://dev.bitly.com/v4). @@ -46,7 +46,7 @@ val bitly = Bitly(File("my.properties")) BITLY_ACCESS_TOKEN=abc123def456ghi789jkl0 ``` -### Gradle +### Gradle, Maven, etc. To use with [Gradle](https://gradle.org/), include the following dependency in your [build](https://github.com/ethauvin/bitly-shorten/blob/master/examples/build.gradle.kts) file: @@ -60,9 +60,11 @@ dependencies { } ``` +Instructions for using with Maven, Ivy, etc. can be found on [Maven Central](https://search.maven.org/artifact/net.thauvin.erik/bitly-shorten/0.9.2/jar). + ### JSON -All implemented methods can return the full API JSON responses: +All implemented API calls can return the full JSON responses: ```kotlin bitly.bitlinks().shorten("https://www.erik.thauvin.net/blog", toJson = true) @@ -76,7 +78,21 @@ bitly.bitlinks().shorten("https://www.erik.thauvin.net/blog", toJson = true) } ``` -Non-implemented methods can also be called directly: +You can also access the last response from implemented API calls using: + +```kotlin +val bitlinks = Bitlinks(apikey) + +val shortUrl = bitlinks.shorten(longUrl) + +val response = bitlinks.lastCallResponse + +if (response.isSuccessful) { + println(response.body) +} +``` + +Non-implemented API calls can also be called directly: ```kotlin val response = bitly.call("/user".toEndPoint(), method = Methods.GET) diff --git a/build.gradle.kts b/build.gradle.kts index 52fef25..a0cc464 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -1,5 +1,4 @@ import com.jfrog.bintray.gradle.tasks.BintrayUploadTask -import org.jetbrains.dokka.gradle.DokkaTask import org.jetbrains.kotlin.gradle.tasks.KotlinCompile import java.io.FileInputStream import java.util.Date @@ -11,11 +10,11 @@ plugins { `maven-publish` id("com.github.ben-manes.versions") version "0.29.0" id("com.jfrog.bintray") version "1.8.5" - id("io.gitlab.arturbosch.detekt") version "1.10.0" + id("io.gitlab.arturbosch.detekt") version "1.11.0" id("net.thauvin.erik.gradle.semver") version "1.0.4" - id("org.jetbrains.dokka") version "0.10.1" - id("org.jetbrains.kotlin.jvm") version "1.3.72" - id("org.jetbrains.kotlin.kapt") version "1.3.72" + id("org.jetbrains.dokka") version "1.4.0-rc" + id("org.jetbrains.kotlin.jvm") version "1.4.0" + id("org.jetbrains.kotlin.kapt") version "1.4.0" id("org.sonarqube") version "3.0" } @@ -32,7 +31,7 @@ var semverProcessor = "net.thauvin.erik:semver:1.2.0" val publicationName = "mavenJava" object VersionInfo { - const val okhttp = "4.8.0" + const val okhttp = "4.8.1" } val versions: VersionInfo by extra { VersionInfo } @@ -57,11 +56,6 @@ repositories { } dependencies { - // Align versions of all Kotlin components - implementation(platform("org.jetbrains.kotlin:kotlin-bom")) - // Use the Kotlin JDK 8 standard library. - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") - implementation("com.squareup.okhttp3:okhttp:${versions.okhttp}") implementation("com.squareup.okhttp3:logging-interceptor:${versions.okhttp}") implementation("org.json:json:20200518") @@ -79,7 +73,7 @@ kapt { } detekt { - baseline = project.rootDir.resolve("detekt-baseline.xml") + baseline = project.rootDir.resolve("config/detekt/baseline.xml") } jacoco { @@ -104,32 +98,13 @@ val sourcesJar by tasks.creating(Jar::class) { } val javadocJar by tasks.creating(Jar::class) { - dependsOn(tasks.dokka) - from(tasks.dokka) + dependsOn(tasks.dokkaJavadoc) + from(tasks.dokkaJavadoc) archiveClassifier.set("javadoc") description = "Assembles a JAR of the generated Javadoc." group = JavaBasePlugin.DOCUMENTATION_GROUP } -val dokkaDocs by tasks.creating(DokkaTask::class) { - outputFormat = "gfm" - outputDirectory = "$projectDir" - - configuration { - moduleName = "docs" - sourceLink { - path = file("$projectDir/src/main/kotlin").toURI().toString().replace("file:", "") - url = "https://github.com/ethauvin/${project.name}/tree/master/src/main/kotlin" - lineSuffix = "#L" - } - - jdkVersion = 8 - - includes = listOf("config/dokka/packages.md") - includeNonPublic = false - } -} - tasks { withType { reports { @@ -156,23 +131,31 @@ tasks { } } - dokka { - outputFormat = "html" - outputDirectory = "$buildDir/javadoc" + dokkaHtml { + outputDirectory = "$projectDir/docs" + + dokkaSourceSets { + configureEach { + jdkVersion = 8 + includes = listOf("config/dokka/packages.md") + sourceLink { + path = "/src/main/kotlin/" + url = "https://github.com/ethauvin/${project.name}/tree/master/src/main/kotlin/" + lineSuffix = "#L" + } - configuration { - sourceLink { - path = file("$projectDir/src/main/kotlin").toURI().toString().replace("file:", "") - url = "https://github.com/ethauvin/${project.name}/tree/master/src/main/kotlin" - lineSuffix = "#L" } - - jdkVersion = 8 - - includes = listOf("config/dokka/packages.md") - includeNonPublic = false } - dependsOn(dokkaDocs) + } + + dokkaJavadoc { + dokkaSourceSets { + configureEach { + jdkVersion = 8 + includes = listOf("config/dokka/packages.md") + } + } + dependsOn(dokkaHtml) } val copyToDeploy by registering(Copy::class) { @@ -244,6 +227,7 @@ bintray { githubReleaseNotesFile = "README.md" vcsUrl = "$mavenUrl.git" setLabels( + "android", "bitlinks", "bitly", "bitly-api", diff --git a/config/detekt/baseline.xml b/config/detekt/baseline.xml new file mode 100644 index 0000000..0142bd2 --- /dev/null +++ b/config/detekt/baseline.xml @@ -0,0 +1,21 @@ + + + + + ComplexMethod:Bitlinks.kt$Bitlinks$ @Synchronized @JvmOverloads fun update( bitlink: String, references: Map<String, String> = emptyMap(), archived: Boolean = false, tags: Array<String> = emptyArray(), created_at: String = Constants.EMPTY, title: String = Constants.EMPTY, deeplinks: Array<Map<String, String>> = emptyArray(), created_by: String = Constants.EMPTY, long_url: String = Constants.EMPTY, client_id: String = Constants.EMPTY, custom_bitlinks: Array<String> = emptyArray(), link: String = Constants.EMPTY, id: String = Constants.EMPTY, toJson: Boolean = false ): String + ComplexMethod:Utils.kt$Utils.Companion$ @JvmOverloads fun call( accessToken: String, endPoint: String, params: Map<String, Any> = emptyMap(), method: Methods = Methods.POST ): CallResponse + FunctionParameterNaming:Bitlinks.kt$Bitlinks$bitlink_id: String + FunctionParameterNaming:Bitlinks.kt$Bitlinks$client_id: String = Constants.EMPTY + FunctionParameterNaming:Bitlinks.kt$Bitlinks$created_at: String = Constants.EMPTY + FunctionParameterNaming:Bitlinks.kt$Bitlinks$created_by: String = Constants.EMPTY + FunctionParameterNaming:Bitlinks.kt$Bitlinks$custom_bitlinks: Array<String> = emptyArray() + FunctionParameterNaming:Bitlinks.kt$Bitlinks$group_guid: String = Constants.EMPTY + FunctionParameterNaming:Bitlinks.kt$Bitlinks$long_url: String + FunctionParameterNaming:Bitlinks.kt$Bitlinks$long_url: String = Constants.EMPTY + FunctionParameterNaming:Bitlinks.kt$Bitlinks$unit_reference: String = Constants.EMPTY + MagicNumber:CallResponse.kt$CallResponse$200 + MagicNumber:CallResponse.kt$CallResponse$299 + NestedBlockDepth:Utils.kt$Utils.Companion$ @JvmOverloads fun call( accessToken: String, endPoint: String, params: Map<String, Any> = emptyMap(), method: Methods = Methods.POST ): CallResponse + NestedBlockDepth:Utils.kt$Utils.Companion$private fun parseBody(endPoint: String, result: Response): String + + diff --git a/detekt-baseline.xml b/detekt-baseline.xml deleted file mode 100644 index a4f19c8..0000000 --- a/detekt-baseline.xml +++ /dev/null @@ -1,21 +0,0 @@ - - - - - ComplexMethod:Bitlinks.kt$Bitlinks$update - ComplexMethod:Utils.kt$Utils.Companion$call - FunctionParameterNaming:Bitlinks.kt$Bitlinks$bitlink_id: String - FunctionParameterNaming:Bitlinks.kt$Bitlinks$client_id: String = Constants.EMPTY - FunctionParameterNaming:Bitlinks.kt$Bitlinks$created_at: String = Constants.EMPTY - FunctionParameterNaming:Bitlinks.kt$Bitlinks$created_by: String = Constants.EMPTY - FunctionParameterNaming:Bitlinks.kt$Bitlinks$custom_bitlinks: Array<String> = emptyArray() - FunctionParameterNaming:Bitlinks.kt$Bitlinks$group_guid: String = Constants.EMPTY - FunctionParameterNaming:Bitlinks.kt$Bitlinks$long_url: String - FunctionParameterNaming:Bitlinks.kt$Bitlinks$long_url: String = Constants.EMPTY - FunctionParameterNaming:Bitlinks.kt$Bitlinks$unit_reference: String = Constants.EMPTY - MagicNumber:CallResponse.kt$CallResponse$200 - MagicNumber:CallResponse.kt$CallResponse$299 - NestedBlockDepth:Utils.kt$Utils.Companion$call - NestedBlockDepth:Utils.kt$Utils.Companion$parseBody - - diff --git a/examples/build.gradle.kts b/examples/build.gradle.kts index b2820cf..236b18e 100644 --- a/examples/build.gradle.kts +++ b/examples/build.gradle.kts @@ -1,5 +1,5 @@ plugins { - id("org.jetbrains.kotlin.jvm") version "1.3.72" + id("org.jetbrains.kotlin.jvm") version "1.4.0" id("com.github.ben-manes.versions") version "0.28.0" application } @@ -15,10 +15,7 @@ repositories { } dependencies { - implementation(platform("org.jetbrains.kotlin:kotlin-bom")) - implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") - - implementation("net.thauvin.erik:bitly-shorten:0.9.2") + implementation("net.thauvin.erik:bitly-shorten:0.9.3") implementation("org.json:json:20200518") } diff --git a/examples/gradle/wrapper/gradle-wrapper.jar b/examples/gradle/wrapper/gradle-wrapper.jar index 62d4c05..e708b1c 100644 Binary files a/examples/gradle/wrapper/gradle-wrapper.jar and b/examples/gradle/wrapper/gradle-wrapper.jar differ diff --git a/examples/gradle/wrapper/gradle-wrapper.properties b/examples/gradle/wrapper/gradle-wrapper.properties index 622ab64..6c9a224 100644 --- a/examples/gradle/wrapper/gradle-wrapper.properties +++ b/examples/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/examples/gradlew b/examples/gradlew index fbd7c51..4f906e0 100644 --- a/examples/gradlew +++ b/examples/gradlew @@ -130,7 +130,7 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath diff --git a/examples/gradlew.bat b/examples/gradlew.bat index 5093609..107acd3 100644 --- a/examples/gradlew.bat +++ b/examples/gradlew.bat @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,21 +64,6 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line @@ -86,7 +71,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @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 %* :end @rem End local scope for the variables with windows NT shell diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar index 62d4c05..e708b1c 100644 Binary files a/gradle/wrapper/gradle-wrapper.jar and b/gradle/wrapper/gradle-wrapper.jar differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties index bb8b2fc..6c9a224 100644 --- a/gradle/wrapper/gradle-wrapper.properties +++ b/gradle/wrapper/gradle-wrapper.properties @@ -1,5 +1,5 @@ distributionBase=GRADLE_USER_HOME distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-6.5.1-bin.zip +distributionUrl=https\://services.gradle.org/distributions/gradle-6.6-bin.zip zipStoreBase=GRADLE_USER_HOME zipStorePath=wrapper/dists diff --git a/gradlew b/gradlew index fbd7c51..4f906e0 100755 --- a/gradlew +++ b/gradlew @@ -130,7 +130,7 @@ fi if [ "$cygwin" = "true" -o "$msys" = "true" ] ; then APP_HOME=`cygpath --path --mixed "$APP_HOME"` CLASSPATH=`cygpath --path --mixed "$CLASSPATH"` - + JAVACMD=`cygpath --unix "$JAVACMD"` # We build the pattern for arguments to be converted via cygpath diff --git a/gradlew.bat b/gradlew.bat index 5093609..107acd3 100644 --- a/gradlew.bat +++ b/gradlew.bat @@ -40,7 +40,7 @@ if defined JAVA_HOME goto findJavaFromJavaHome set JAVA_EXE=java.exe %JAVA_EXE% -version >NUL 2>&1 -if "%ERRORLEVEL%" == "0" goto init +if "%ERRORLEVEL%" == "0" goto execute echo. echo ERROR: JAVA_HOME is not set and no 'java' command could be found in your PATH. @@ -54,7 +54,7 @@ goto fail set JAVA_HOME=%JAVA_HOME:"=% set JAVA_EXE=%JAVA_HOME%/bin/java.exe -if exist "%JAVA_EXE%" goto init +if exist "%JAVA_EXE%" goto execute echo. echo ERROR: JAVA_HOME is set to an invalid directory: %JAVA_HOME% @@ -64,21 +64,6 @@ echo location of your Java installation. goto fail -:init -@rem Get command-line arguments, handling Windows variants - -if not "%OS%" == "Windows_NT" goto win9xME_args - -:win9xME_args -@rem Slurp the command line arguments. -set CMD_LINE_ARGS= -set _SKIP=2 - -:win9xME_args_slurp -if "x%~1" == "x" goto execute - -set CMD_LINE_ARGS=%* - :execute @rem Setup the command line @@ -86,7 +71,7 @@ set CLASSPATH=%APP_HOME%\gradle\wrapper\gradle-wrapper.jar @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 %* :end @rem End local scope for the variables with windows NT shell diff --git a/src/test/kotlin/net/thauvin/erik/bitly/BitlyTest.kt b/src/test/kotlin/net/thauvin/erik/bitly/BitlyTest.kt index 5bdeaa2..c3f0f8f 100644 --- a/src/test/kotlin/net/thauvin/erik/bitly/BitlyTest.kt +++ b/src/test/kotlin/net/thauvin/erik/bitly/BitlyTest.kt @@ -126,7 +126,7 @@ class BitlyTest { @Test fun `bitlinks lastCallResponse`() { val bl = Bitlinks(bitly.accessToken) - bl.shorten(longUrl, domain="bit.ly") + bl.shorten(longUrl, domain = "bit.ly") assertEquals(true, bl.lastCallResponse.isSuccessful, "is successful") assertEquals(200, bl.lastCallResponse.resultCode, "resultCode == 200") assertTrue(bl.lastCallResponse.body.contains("\"link\":\"$shortUrl\""), "valid body") diff --git a/version.properties b/version.properties index 29dbe9b..bf27b82 100644 --- a/version.properties +++ b/version.properties @@ -3,6 +3,6 @@ version.buildmeta= version.major=0 version.minor=9 -version.patch=2 +version.patch=3 version.prerelease= -version.semver=0.9.2 +version.semver=0.9.3