Cleanup.
This commit is contained in:
parent
3971b2fc36
commit
e97c13fc4c
12 changed files with 132 additions and 48 deletions
2
.idea/bitly-shorten.iml
generated
2
.idea/bitly-shorten.iml
generated
|
@ -1,2 +0,0 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<module type="JAVA_MODULE" version="4" />
|
6
.idea/compiler.xml
generated
Normal file
6
.idea/compiler.xml
generated
Normal file
|
@ -0,0 +1,6 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="1.8" />
|
||||
</component>
|
||||
</project>
|
5
.idea/jarRepositories.xml
generated
5
.idea/jarRepositories.xml
generated
|
@ -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>
|
65
.idea/libraries-with-intellij-classes.xml
generated
Normal file
65
.idea/libraries-with-intellij-classes.xml
generated
Normal 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
2
.idea/misc.xml
generated
|
@ -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">
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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<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>
|
||||
|
|
4
pom.xml
4
pom.xml
|
@ -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>
|
||||
|
|
|
@ -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.
|
||||
|
@ -124,8 +126,7 @@ open class Bitlinks(private val accessToken: String) {
|
|||
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)
|
||||
|
|
|
@ -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 {
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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(), "")
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue