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="name" value="MavenLocal" />
|
||||||
<option name="url" value="file:$MAVEN_REPOSITORY$/" />
|
<option name="url" value="file:$MAVEN_REPOSITORY$/" />
|
||||||
</remote-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>
|
</component>
|
||||||
</project>
|
</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">
|
<component name="JavaScriptSettings">
|
||||||
<option name="languageLevel" value="ES6" />
|
<option name="languageLevel" value="ES6" />
|
||||||
</component>
|
</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" />
|
<output url="file://$PROJECT_DIR$/build/classes" />
|
||||||
</component>
|
</component>
|
||||||
<component name="ProjectType">
|
<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.TestExceptionFormat
|
||||||
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
import org.gradle.api.tasks.testing.logging.TestLogEvent
|
||||||
|
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
||||||
|
import java.net.URL
|
||||||
|
|
||||||
plugins {
|
plugins {
|
||||||
id("com.github.ben-manes.versions") version "0.39.0"
|
id("com.github.ben-manes.versions") version "0.39.0"
|
||||||
|
@ -138,9 +138,9 @@ tasks {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
dokkaJavadoc {
|
dokkaJavadoc {
|
||||||
dokkaSourceSets {
|
dokkaSourceSets {
|
||||||
configureEach {
|
configureEach {
|
||||||
jdkVersion.set(8)
|
jdkVersion.set(8)
|
||||||
includes.from("config/dokka/packages.md")
|
includes.from("config/dokka/packages.md")
|
||||||
|
@ -231,10 +231,10 @@ publishing {
|
||||||
maven {
|
maven {
|
||||||
name = "ossrh"
|
name = "ossrh"
|
||||||
project.afterEvaluate {
|
project.afterEvaluate {
|
||||||
url = if (version.toString().contains("SNAPSHOT"))
|
url = if (version.toString().contains("SNAPSHOT"))
|
||||||
uri("https://oss.sonatype.org/content/repositories/snapshots/")
|
uri("https://oss.sonatype.org/content/repositories/snapshots/")
|
||||||
else
|
else
|
||||||
uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
uri("https://oss.sonatype.org/service/local/staging/deploy/maven2/")
|
||||||
}
|
}
|
||||||
credentials(PasswordCredentials::class)
|
credentials(PasswordCredentials::class)
|
||||||
}
|
}
|
||||||
|
|
|
@ -14,7 +14,16 @@
|
||||||
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$long_url: String = Constants.EMPTY</ID>
|
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$long_url: String = Constants.EMPTY</ID>
|
||||||
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$unit_reference: 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$200</ID>
|
||||||
|
<ID>MagicNumber:CallResponse.kt$CallResponse$201</ID>
|
||||||
<ID>MagicNumber:CallResponse.kt$CallResponse$299</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$ @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>
|
<ID>NestedBlockDepth:Utils.kt$Utils.Companion$private fun parseBody(endPoint: String, result: Response): String</ID>
|
||||||
</CurrentIssues>
|
</CurrentIssues>
|
||||||
|
|
4
pom.xml
4
pom.xml
|
@ -40,7 +40,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-bom</artifactId>
|
<artifactId>kotlin-bom</artifactId>
|
||||||
<version>1.5.0</version>
|
<version>1.5.10</version>
|
||||||
<type>pom</type>
|
<type>pom</type>
|
||||||
<scope>import</scope>
|
<scope>import</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
@ -50,7 +50,7 @@
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>org.jetbrains.kotlin</groupId>
|
<groupId>org.jetbrains.kotlin</groupId>
|
||||||
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
<artifactId>kotlin-stdlib-jdk8</artifactId>
|
||||||
<version>1.5.0</version>
|
<version>1.5.10</version>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
|
|
|
@ -81,10 +81,10 @@ open class Bitlinks(private val accessToken: String) {
|
||||||
accessToken,
|
accessToken,
|
||||||
("/bitlinks/${bitlink.removeHttp()}/clicks/summary").toEndPoint(),
|
("/bitlinks/${bitlink.removeHttp()}/clicks/summary").toEndPoint(),
|
||||||
mapOf(
|
mapOf(
|
||||||
"unit" to unit.toString().lowercase(),
|
"unit" to unit.toString().lowercase(),
|
||||||
"units" to units.toString(),
|
"units" to units.toString(),
|
||||||
"size" to size.toString(),
|
"size" to size.toString(),
|
||||||
"unit_reference" to unit_reference
|
"unit_reference" to unit_reference
|
||||||
),
|
),
|
||||||
Methods.GET
|
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.
|
* 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 long_url The long URL.
|
||||||
* @param toJson Returns the full JSON response if `true`.
|
* @param toJson Returns the full JSON response if `true`.
|
||||||
* @return The shorten URL or an empty string on error.
|
* @return The shorten URL or an empty string on error.
|
||||||
|
@ -118,14 +120,13 @@ open class Bitlinks(private val accessToken: String) {
|
||||||
lastCallResponse = Utils.call(
|
lastCallResponse = Utils.call(
|
||||||
accessToken,
|
accessToken,
|
||||||
"/bitlinks".toEndPoint(),
|
"/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 (domain.isNotBlank()) put("domain", domain)
|
||||||
if (title.isNotBlank()) put("title", title)
|
if (title.isNotBlank()) put("title", title)
|
||||||
if (group_guid.isNotBlank()) put("group_guid", group_guid)
|
if (group_guid.isNotBlank()) put("group_guid", group_guid)
|
||||||
if (tags.isNotEmpty()) put("tags", tags)
|
if (tags.isNotEmpty()) put("tags", tags)
|
||||||
if (deeplinks.isNotEmpty()) put("deeplinks", deeplinks)
|
if (deeplinks.isNotEmpty()) put("deeplinks", deeplinks)
|
||||||
},
|
}
|
||||||
Methods.POST
|
|
||||||
)
|
)
|
||||||
link = parseJsonResponse(lastCallResponse, "link", link, toJson)
|
link = parseJsonResponse(lastCallResponse, "link", link, toJson)
|
||||||
}
|
}
|
||||||
|
@ -149,8 +150,7 @@ open class Bitlinks(private val accessToken: String) {
|
||||||
lastCallResponse = Utils.call(
|
lastCallResponse = Utils.call(
|
||||||
accessToken,
|
accessToken,
|
||||||
"/expand".toEndPoint(),
|
"/expand".toEndPoint(),
|
||||||
mapOf("bitlink_id" to bitlink_id.removeHttp()),
|
mapOf("bitlink_id" to bitlink_id.removeHttp())
|
||||||
Methods.POST
|
|
||||||
)
|
)
|
||||||
longUrl = parseJsonResponse(lastCallResponse, "long_url", longUrl, toJson)
|
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.
|
* See the [Bit.ly API](https://dev.bitly.com/api-reference#createBitlink) for more information.
|
||||||
*
|
*
|
||||||
* @param long_url The long URL.
|
* @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`.
|
* @param toJson Returns the full JSON response if `true`.
|
||||||
* @return The short URL or the [long_url] on error.
|
* @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()) {
|
if (!long_url.isValidUrl()) {
|
||||||
Utils.logger.severe("Please specify a valid URL to shorten.")
|
Utils.logger.severe("Please specify a valid URL to shorten.")
|
||||||
} else {
|
} 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 (group_guid.isNotBlank()) put("group_guid", group_guid)
|
||||||
if (domain.isNotBlank()) put("domain", domain)
|
if (domain.isNotBlank()) put("domain", domain)
|
||||||
put("long_url", long_url)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
lastCallResponse = Utils.call(accessToken, "/shorten".toEndPoint(), params)
|
lastCallResponse = Utils.call(accessToken, "/shorten".toEndPoint(), params)
|
||||||
|
@ -247,19 +248,19 @@ open class Bitlinks(private val accessToken: String) {
|
||||||
if (bitlink.isNotBlank()) {
|
if (bitlink.isNotBlank()) {
|
||||||
lastCallResponse = Utils.call(
|
lastCallResponse = Utils.call(
|
||||||
accessToken, "/bitlinks/${bitlink.removeHttp()}".toEndPoint(), mutableMapOf<String, Any>().apply {
|
accessToken, "/bitlinks/${bitlink.removeHttp()}".toEndPoint(), mutableMapOf<String, Any>().apply {
|
||||||
if (references.isNotEmpty()) put("references", references)
|
if (references.isNotEmpty()) put("references", references)
|
||||||
if (archived) put("archived", archived)
|
if (archived) put("archived", archived)
|
||||||
if (tags.isNotEmpty()) put("tags", tags)
|
if (tags.isNotEmpty()) put("tags", tags)
|
||||||
if (created_at.isNotBlank()) put("created_at", created_at)
|
if (created_at.isNotBlank()) put("created_at", created_at)
|
||||||
if (title.isNotBlank()) put("title", title)
|
if (title.isNotBlank()) put("title", title)
|
||||||
if (deeplinks.isNotEmpty()) put("deeplinks", deeplinks)
|
if (deeplinks.isNotEmpty()) put("deeplinks", deeplinks)
|
||||||
if (created_by.isNotBlank()) put("created_by", created_by)
|
if (created_by.isNotBlank()) put("created_by", created_by)
|
||||||
if (long_url.isNotBlank()) put("long_url", long_url)
|
if (long_url.isNotBlank()) put("long_url", long_url)
|
||||||
if (client_id.isNotBlank()) put("client_id", client_id)
|
if (client_id.isNotBlank()) put("client_id", client_id)
|
||||||
if (custom_bitlinks.isNotEmpty()) put("custom_bitlinks", custom_bitlinks)
|
if (custom_bitlinks.isNotEmpty()) put("custom_bitlinks", custom_bitlinks)
|
||||||
if (link.isNotBlank()) put("link", link)
|
if (link.isNotBlank()) put("link", link)
|
||||||
if (id.isNotBlank()) put("id", id)
|
if (id.isNotBlank()) put("id", id)
|
||||||
},
|
},
|
||||||
Methods.PATCH
|
Methods.PATCH
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -52,7 +52,7 @@ open class Bitly() {
|
||||||
?: (System.getProperty(Constants.ENV_ACCESS_TOKEN) ?: Constants.EMPTY)
|
?: (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.
|
* @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].
|
* @param key The property key containing the [API Access Token][accessToken].
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
@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].
|
* @param key The property key containing the [API Access Token][accessToken].
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@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].
|
* @param key The property key containing the [API Access Token][accessToken].
|
||||||
*/
|
*/
|
||||||
@Suppress("unused")
|
@Suppress("unused")
|
||||||
|
@ -111,7 +111,7 @@ open class Bitly() {
|
||||||
* @param endPoint The REST endpoint. (eg. `https://api-ssl.bitly.com/v4/shorten`)
|
* @param endPoint The REST endpoint. (eg. `https://api-ssl.bitly.com/v4/shorten`)
|
||||||
* @param params The request parameters key/value map.
|
* @param params The request parameters key/value map.
|
||||||
* @param method The submission [Method][Methods].
|
* @param method The submission [Method][Methods].
|
||||||
* @return The response (JSON) from the API.
|
* @return A [CallResponse] object.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun call(endPoint: String, params: Map<String, Any> = emptyMap(), method: Methods = Methods.POST): CallResponse {
|
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.
|
* Provides a data class to hold the JSON response.
|
||||||
*/
|
*/
|
||||||
|
@Suppress("unused")
|
||||||
data class CallResponse(val body: String = Constants.EMPTY_JSON, val resultCode: Int = -1) {
|
data class CallResponse(val body: String = Constants.EMPTY_JSON, val resultCode: Int = -1) {
|
||||||
val isSuccessful: Boolean
|
val isSuccessful: Boolean
|
||||||
get() = resultCode in 200..299
|
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 endPoint The REST endpoint. (eg. `https://api-ssl.bitly.com/v4/shorten`)
|
||||||
* @param params The request parameters key/value map.
|
* @param params The request parameters key/value map.
|
||||||
* @param method The submission [Method][Methods].
|
* @param method The submission [Method][Methods].
|
||||||
* @return The response (JSON) from the API.
|
* @return A [CallResponse] object.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun call(
|
fun call(
|
||||||
|
@ -99,8 +99,7 @@ open class Utils private constructor() {
|
||||||
}.addHeader("Authorization", "Bearer $accessToken")
|
}.addHeader("Authorization", "Bearer $accessToken")
|
||||||
|
|
||||||
val result = createHttpClient().newCall(builder.build()).execute()
|
val result = createHttpClient().newCall(builder.build()).execute()
|
||||||
response.body = parseBody(endPoint, result)
|
return CallResponse(parseBody(endPoint, result), result.code)
|
||||||
response.resultCode = result.code
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return response
|
return response
|
||||||
|
@ -162,7 +161,7 @@ open class Utils private constructor() {
|
||||||
* Removes http(s) scheme from string.
|
* Removes http(s) scheme from string.
|
||||||
*/
|
*/
|
||||||
fun String.removeHttp(): 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