diff --git a/.idea/bitly-shorten.iml b/.idea/bitly-shorten.iml
deleted file mode 100644
index 78b2cc5..0000000
--- a/.idea/bitly-shorten.iml
+++ /dev/null
@@ -1,2 +0,0 @@
-
-
\ No newline at end of file
diff --git a/.idea/compiler.xml b/.idea/compiler.xml
new file mode 100644
index 0000000..61a9130
--- /dev/null
+++ b/.idea/compiler.xml
@@ -0,0 +1,6 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/jarRepositories.xml b/.idea/jarRepositories.xml
index d80efca..6b0a35d 100644
--- a/.idea/jarRepositories.xml
+++ b/.idea/jarRepositories.xml
@@ -36,5 +36,10 @@
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/libraries-with-intellij-classes.xml b/.idea/libraries-with-intellij-classes.xml
new file mode 100644
index 0000000..9fa3156
--- /dev/null
+++ b/.idea/libraries-with-intellij-classes.xml
@@ -0,0 +1,65 @@
+
+
+
+
+
+
\ No newline at end of file
diff --git a/.idea/misc.xml b/.idea/misc.xml
index 05b6e27..a3609c8 100644
--- a/.idea/misc.xml
+++ b/.idea/misc.xml
@@ -12,7 +12,7 @@
-
+
diff --git a/build.gradle.kts b/build.gradle.kts
index 205de5f..d8a6c51 100644
--- a/build.gradle.kts
+++ b/build.gradle.kts
@@ -1,7 +1,7 @@
-import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
-import java.net.URL
import org.gradle.api.tasks.testing.logging.TestExceptionFormat
import org.gradle.api.tasks.testing.logging.TestLogEvent
+import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
+import java.net.URL
plugins {
id("com.github.ben-manes.versions") version "0.39.0"
@@ -138,9 +138,9 @@ tasks {
}
}
}
-
+
dokkaJavadoc {
- dokkaSourceSets {
+ dokkaSourceSets {
configureEach {
jdkVersion.set(8)
includes.from("config/dokka/packages.md")
@@ -231,10 +231,10 @@ publishing {
maven {
name = "ossrh"
project.afterEvaluate {
- url = if (version.toString().contains("SNAPSHOT"))
- uri("https://oss.sonatype.org/content/repositories/snapshots/")
- else
- uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
+ url = if (version.toString().contains("SNAPSHOT"))
+ uri("https://oss.sonatype.org/content/repositories/snapshots/")
+ else
+ uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
}
credentials(PasswordCredentials::class)
}
diff --git a/config/detekt/baseline.xml b/config/detekt/baseline.xml
index 3e7f711..8c10719 100644
--- a/config/detekt/baseline.xml
+++ b/config/detekt/baseline.xml
@@ -14,7 +14,16 @@
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$201
MagicNumber:CallResponse.kt$CallResponse$299
+ MagicNumber:CallResponse.kt$CallResponse$400
+ MagicNumber:CallResponse.kt$CallResponse$402
+ MagicNumber:CallResponse.kt$CallResponse$403
+ MagicNumber:CallResponse.kt$CallResponse$404
+ MagicNumber:CallResponse.kt$CallResponse$417
+ MagicNumber:CallResponse.kt$CallResponse$422
+ MagicNumber:CallResponse.kt$CallResponse$500
+ MagicNumber:CallResponse.kt$CallResponse$503
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/pom.xml b/pom.xml
index 8dd651a..96bf1b9 100644
--- a/pom.xml
+++ b/pom.xml
@@ -40,7 +40,7 @@
org.jetbrains.kotlin
kotlin-bom
- 1.5.0
+ 1.5.10
pom
import
@@ -50,7 +50,7 @@
org.jetbrains.kotlin
kotlin-stdlib-jdk8
- 1.5.0
+ 1.5.10
compile
diff --git a/src/main/kotlin/net/thauvin/erik/bitly/Bitlinks.kt b/src/main/kotlin/net/thauvin/erik/bitly/Bitlinks.kt
index 6ed046b..e43a9b3 100644
--- a/src/main/kotlin/net/thauvin/erik/bitly/Bitlinks.kt
+++ b/src/main/kotlin/net/thauvin/erik/bitly/Bitlinks.kt
@@ -81,10 +81,10 @@ open class Bitlinks(private val accessToken: String) {
accessToken,
("/bitlinks/${bitlink.removeHttp()}/clicks/summary").toEndPoint(),
mapOf(
- "unit" to unit.toString().lowercase(),
+ "unit" to unit.toString().lowercase(),
"units" to units.toString(),
- "size" to size.toString(),
- "unit_reference" to unit_reference
+ "size" to size.toString(),
+ "unit_reference" to unit_reference
),
Methods.GET
)
@@ -98,6 +98,8 @@ open class Bitlinks(private val accessToken: String) {
*
* See the [Bit.ly API](https://dev.bitly.com/api-reference#createFullBitlink) for more information.
*
+ * @param domain A branded short domain or `bit.ly` by default.
+ * @param group_guid A GUID for a Bitly group.
* @param long_url The long URL.
* @param toJson Returns the full JSON response if `true`.
* @return The shorten URL or an empty string on error.
@@ -118,14 +120,13 @@ open class Bitlinks(private val accessToken: String) {
lastCallResponse = Utils.call(
accessToken,
"/bitlinks".toEndPoint(),
- mutableMapOf("long_url" to long_url).apply {
+ mutableMapOf("long_url" to long_url).apply {
if (domain.isNotBlank()) put("domain", domain)
if (title.isNotBlank()) put("title", title)
if (group_guid.isNotBlank()) put("group_guid", group_guid)
if (tags.isNotEmpty()) put("tags", tags)
if (deeplinks.isNotEmpty()) put("deeplinks", deeplinks)
- },
- Methods.POST
+ }
)
link = parseJsonResponse(lastCallResponse, "link", link, toJson)
}
@@ -149,8 +150,7 @@ open class Bitlinks(private val accessToken: String) {
lastCallResponse = Utils.call(
accessToken,
"/expand".toEndPoint(),
- mapOf("bitlink_id" to bitlink_id.removeHttp()),
- Methods.POST
+ mapOf("bitlink_id" to bitlink_id.removeHttp())
)
longUrl = parseJsonResponse(lastCallResponse, "long_url", longUrl, toJson)
}
@@ -187,6 +187,8 @@ open class Bitlinks(private val accessToken: String) {
* See the [Bit.ly API](https://dev.bitly.com/api-reference#createBitlink) for more information.
*
* @param long_url The long URL.
+ * @param group_guid A GUID for a Bitly group.
+ * @param domain A branded short domain or `bit.ly` by default.
* @param toJson Returns the full JSON response if `true`.
* @return The short URL or the [long_url] on error.
*/
@@ -202,10 +204,9 @@ open class Bitlinks(private val accessToken: String) {
if (!long_url.isValidUrl()) {
Utils.logger.severe("Please specify a valid URL to shorten.")
} else {
- val params = mutableMapOf().apply {
+ val params = mutableMapOf("long_url" to long_url).apply {
if (group_guid.isNotBlank()) put("group_guid", group_guid)
if (domain.isNotBlank()) put("domain", domain)
- put("long_url", long_url)
}
lastCallResponse = Utils.call(accessToken, "/shorten".toEndPoint(), params)
@@ -247,19 +248,19 @@ open class Bitlinks(private val accessToken: String) {
if (bitlink.isNotBlank()) {
lastCallResponse = Utils.call(
accessToken, "/bitlinks/${bitlink.removeHttp()}".toEndPoint(), mutableMapOf().apply {
- if (references.isNotEmpty()) put("references", references)
- if (archived) put("archived", archived)
- if (tags.isNotEmpty()) put("tags", tags)
- if (created_at.isNotBlank()) put("created_at", created_at)
- if (title.isNotBlank()) put("title", title)
- if (deeplinks.isNotEmpty()) put("deeplinks", deeplinks)
- if (created_by.isNotBlank()) put("created_by", created_by)
- if (long_url.isNotBlank()) put("long_url", long_url)
- if (client_id.isNotBlank()) put("client_id", client_id)
- if (custom_bitlinks.isNotEmpty()) put("custom_bitlinks", custom_bitlinks)
- if (link.isNotBlank()) put("link", link)
- if (id.isNotBlank()) put("id", id)
- },
+ if (references.isNotEmpty()) put("references", references)
+ if (archived) put("archived", archived)
+ if (tags.isNotEmpty()) put("tags", tags)
+ if (created_at.isNotBlank()) put("created_at", created_at)
+ if (title.isNotBlank()) put("title", title)
+ if (deeplinks.isNotEmpty()) put("deeplinks", deeplinks)
+ if (created_by.isNotBlank()) put("created_by", created_by)
+ if (long_url.isNotBlank()) put("long_url", long_url)
+ if (client_id.isNotBlank()) put("client_id", client_id)
+ if (custom_bitlinks.isNotEmpty()) put("custom_bitlinks", custom_bitlinks)
+ if (link.isNotBlank()) put("link", link)
+ if (id.isNotBlank()) put("id", id)
+ },
Methods.PATCH
)
diff --git a/src/main/kotlin/net/thauvin/erik/bitly/Bitly.kt b/src/main/kotlin/net/thauvin/erik/bitly/Bitly.kt
index d31a2c8..731b826 100644
--- a/src/main/kotlin/net/thauvin/erik/bitly/Bitly.kt
+++ b/src/main/kotlin/net/thauvin/erik/bitly/Bitly.kt
@@ -52,7 +52,7 @@ open class Bitly() {
?: (System.getProperty(Constants.ENV_ACCESS_TOKEN) ?: Constants.EMPTY)
/**
- * Creates a new instance using an [API Access Token][Bitly.accessToken].
+ * Creates a new instance using an [API Access Token][accessToken].
*
* @param accessToken The API access token.
*/
@@ -62,9 +62,9 @@ open class Bitly() {
}
/**
- * Creates a new instance using a [Properties][properties] and [Property Key][key].
+ * Creates a new instance using a properties and property key.
*
- * @param properties The properties.
+ * @param properties The properties containing the [API Access Token][accessToken].
* @param key The property key containing the [API Access Token][accessToken].
*/
@Suppress("unused")
@@ -74,9 +74,9 @@ open class Bitly() {
}
/**
- * Creates a new instance using a [Properties File Path][propertiesFilePath] and [Property Key][key].
+ * Creates a new instance using a properties file path and property key.
*
- * @param propertiesFilePath The properties file path.
+ * @param propertiesFilePath The file path of the properties containing the [API Access Token][accessToken].
* @param key The property key containing the [API Access Token][accessToken].
*/
@JvmOverloads
@@ -91,9 +91,9 @@ open class Bitly() {
}
/**
- * Creates a new instance using a [Properties File][propertiesFile] and [Property Key][key].
+ * Creates a new instance using a properties file and property key.
*
- * @param propertiesFile The properties file.
+ * @param propertiesFile The properties file containing the [API Access Token][accessToken].
* @param key The property key containing the [API Access Token][accessToken].
*/
@Suppress("unused")
@@ -111,7 +111,7 @@ open class Bitly() {
* @param endPoint The REST endpoint. (eg. `https://api-ssl.bitly.com/v4/shorten`)
* @param params The request parameters key/value map.
* @param method The submission [Method][Methods].
- * @return The response (JSON) from the API.
+ * @return A [CallResponse] object.
*/
@JvmOverloads
fun call(endPoint: String, params: Map = emptyMap(), method: Methods = Methods.POST): CallResponse {
diff --git a/src/main/kotlin/net/thauvin/erik/bitly/CallResponse.kt b/src/main/kotlin/net/thauvin/erik/bitly/CallResponse.kt
index 4fe7a96..d2b2e2d 100644
--- a/src/main/kotlin/net/thauvin/erik/bitly/CallResponse.kt
+++ b/src/main/kotlin/net/thauvin/erik/bitly/CallResponse.kt
@@ -35,6 +35,7 @@ package net.thauvin.erik.bitly
/**
* Provides a data class to hold the JSON response.
*/
+@Suppress("unused")
data class CallResponse(val body: String = Constants.EMPTY_JSON, val resultCode: Int = -1) {
val isSuccessful: Boolean
get() = resultCode in 200..299
diff --git a/src/main/kotlin/net/thauvin/erik/bitly/Utils.kt b/src/main/kotlin/net/thauvin/erik/bitly/Utils.kt
index 5e91a7d..12e27cb 100644
--- a/src/main/kotlin/net/thauvin/erik/bitly/Utils.kt
+++ b/src/main/kotlin/net/thauvin/erik/bitly/Utils.kt
@@ -59,7 +59,7 @@ open class Utils private constructor() {
* @param endPoint The REST endpoint. (eg. `https://api-ssl.bitly.com/v4/shorten`)
* @param params The request parameters key/value map.
* @param method The submission [Method][Methods].
- * @return The response (JSON) from the API.
+ * @return A [CallResponse] object.
*/
@JvmOverloads
fun call(
@@ -99,8 +99,7 @@ open class Utils private constructor() {
}.addHeader("Authorization", "Bearer $accessToken")
val result = createHttpClient().newCall(builder.build()).execute()
- response.body = parseBody(endPoint, result)
- response.resultCode = result.code
+ return CallResponse(parseBody(endPoint, result), result.code)
}
}
return response
@@ -162,7 +161,7 @@ open class Utils private constructor() {
* Removes http(s) scheme from string.
*/
fun String.removeHttp(): String {
- return this.replaceFirst(Regex("^[Hh][Tt]{2}[Pp][Ss]?://"), "")
+ return this.replaceFirst("^[Hh][Tt]{2}[Pp][Ss]?://".toRegex(), "")
}
/**