This commit is contained in:
Erik C. Thauvin 2021-06-05 02:23:59 -07:00
parent 3971b2fc36
commit e97c13fc4c
12 changed files with 132 additions and 48 deletions

View file

@ -1,2 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4" />

6
.idea/compiler.xml generated Normal file
View file

@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="CompilerConfiguration">
<bytecodeTargetLevel target="1.8" />
</component>
</project>

View file

@ -36,5 +36,10 @@
<option name="name" value="MavenLocal" />
<option name="url" value="file:$MAVEN_REPOSITORY$/" />
</remote-repository>
<remote-repository>
<option name="id" value="maven" />
<option name="name" value="maven" />
<option name="url" value="https://oss.sonatype.org/content/repositories/snapshots" />
</remote-repository>
</component>
</project>

View file

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="libraries-with-intellij-classes">
<option name="intellijApiContainingLibraries">
<list>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIU" />
<option name="groupId" value="com.jetbrains.intellij.idea" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIU" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIC" />
<option name="groupId" value="com.jetbrains.intellij.idea" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="ideaIC" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPY" />
<option name="groupId" value="com.jetbrains.intellij.pycharm" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPY" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPC" />
<option name="groupId" value="com.jetbrains.intellij.pycharm" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="pycharmPC" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="clion" />
<option name="groupId" value="com.jetbrains.intellij.clion" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="clion" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="riderRD" />
<option name="groupId" value="com.jetbrains.intellij.rider" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="riderRD" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="goland" />
<option name="groupId" value="com.jetbrains.intellij.goland" />
</LibraryCoordinatesState>
<LibraryCoordinatesState>
<option name="artifactId" value="goland" />
<option name="groupId" value="com.jetbrains" />
</LibraryCoordinatesState>
</list>
</option>
</component>
</project>

2
.idea/misc.xml generated
View file

@ -12,7 +12,7 @@
<component name="JavaScriptSettings">
<option name="languageLevel" value="ES6" />
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="false" project-jdk-name="1.8" project-jdk-type="JavaSDK">
<component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" project-jdk-name="15" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/build/classes" />
</component>
<component name="ProjectType">

View file

@ -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)
}

View file

@ -14,7 +14,16 @@
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$long_url: String = Constants.EMPTY</ID>
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$unit_reference: String = Constants.EMPTY</ID>
<ID>MagicNumber:CallResponse.kt$CallResponse$200</ID>
<ID>MagicNumber:CallResponse.kt$CallResponse$201</ID>
<ID>MagicNumber:CallResponse.kt$CallResponse$299</ID>
<ID>MagicNumber:CallResponse.kt$CallResponse$400</ID>
<ID>MagicNumber:CallResponse.kt$CallResponse$402</ID>
<ID>MagicNumber:CallResponse.kt$CallResponse$403</ID>
<ID>MagicNumber:CallResponse.kt$CallResponse$404</ID>
<ID>MagicNumber:CallResponse.kt$CallResponse$417</ID>
<ID>MagicNumber:CallResponse.kt$CallResponse$422</ID>
<ID>MagicNumber:CallResponse.kt$CallResponse$500</ID>
<ID>MagicNumber:CallResponse.kt$CallResponse$503</ID>
<ID>NestedBlockDepth:Utils.kt$Utils.Companion$ @JvmOverloads fun call( accessToken: String, endPoint: String, params: Map&lt;String, Any> = emptyMap(), method: Methods = Methods.POST ): CallResponse</ID>
<ID>NestedBlockDepth:Utils.kt$Utils.Companion$private fun parseBody(endPoint: String, result: Response): String</ID>
</CurrentIssues>

View file

@ -40,7 +40,7 @@
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-bom</artifactId>
<version>1.5.0</version>
<version>1.5.10</version>
<type>pom</type>
<scope>import</scope>
</dependency>
@ -50,7 +50,7 @@
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib-jdk8</artifactId>
<version>1.5.0</version>
<version>1.5.10</version>
<scope>compile</scope>
</dependency>
<dependency>

View file

@ -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<String, Any>("long_url" to long_url).apply {
mutableMapOf<String, Any>("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<String, String>().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<String, Any>().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
)

View file

@ -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<String, Any> = emptyMap(), method: Methods = Methods.POST): CallResponse {

View file

@ -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

View file

@ -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(), "")
}
/**