Added EMPTY constant.
This commit is contained in:
parent
d77b3cce72
commit
abdae1cc77
6 changed files with 18 additions and 18 deletions
|
@ -2,12 +2,8 @@
|
||||||
<SmellBaseline>
|
<SmellBaseline>
|
||||||
<Blacklist></Blacklist>
|
<Blacklist></Blacklist>
|
||||||
<Whitelist>
|
<Whitelist>
|
||||||
<ID>ComplexMethod:Utils.kt$Utils.Companion$call</ID>
|
|
||||||
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$bitlink_id: String</ID>
|
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$bitlink_id: String</ID>
|
||||||
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$group_guid: String = ""</ID>
|
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$group_guid: String = Constants.EMPTY</ID>
|
||||||
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$long_url: String</ID>
|
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$long_url: String</ID>
|
||||||
<ID>NestedBlockDepth:Utils.kt$Utils.Companion$call</ID>
|
|
||||||
<ID>NestedBlockDepth:Utils.kt$Utils.Companion$logApiError</ID>
|
|
||||||
<ID>ReturnCount:Bitlinks.kt$Bitlinks$private fun parseJsonResponse(response: String, key: String, default: String, isJson: Boolean): String</ID>
|
|
||||||
</Whitelist>
|
</Whitelist>
|
||||||
</SmellBaseline>
|
</SmellBaseline>
|
||||||
|
|
|
@ -53,7 +53,7 @@ class Bitlinks(private val accessToken: String) {
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun expand(bitlink_id: String, isJson: Boolean = false): String {
|
fun expand(bitlink_id: String, isJson: Boolean = false): String {
|
||||||
var longUrl = if (isJson) "{}" else ""
|
var longUrl = if (isJson) "{}" else Constants.EMPTY
|
||||||
if (bitlink_id.isNotBlank()) {
|
if (bitlink_id.isNotBlank()) {
|
||||||
val response = Utils.call(
|
val response = Utils.call(
|
||||||
accessToken,
|
accessToken,
|
||||||
|
@ -86,8 +86,13 @@ class Bitlinks(private val accessToken: String) {
|
||||||
* @return THe short URL or JSON API response.
|
* @return THe short URL or JSON API response.
|
||||||
*/
|
*/
|
||||||
@JvmOverloads
|
@JvmOverloads
|
||||||
fun shorten(long_url: String, group_guid: String = "", domain: String = "", isJson: Boolean = false): String {
|
fun shorten(
|
||||||
var bitlink = if (isJson) "{}" else ""
|
long_url: String,
|
||||||
|
group_guid: String = Constants.EMPTY,
|
||||||
|
domain: String = Constants.EMPTY,
|
||||||
|
isJson: Boolean = false
|
||||||
|
): String {
|
||||||
|
var bitlink = if (isJson) "{}" else Constants.EMPTY
|
||||||
if (!Utils.validateUrl(long_url)) {
|
if (!Utils.validateUrl(long_url)) {
|
||||||
Utils.logger.severe("Please specify a valid URL to shorten.")
|
Utils.logger.severe("Please specify a valid URL to shorten.")
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -51,7 +51,7 @@ enum class Methods {
|
||||||
*/
|
*/
|
||||||
open class Bitly() {
|
open class Bitly() {
|
||||||
/** The API access token. **/
|
/** The API access token. **/
|
||||||
var accessToken: String = System.getenv(Constants.ENV_ACCESS_TOKEN) ?: ""
|
var accessToken: String = System.getenv(Constants.ENV_ACCESS_TOKEN) ?: Constants.EMPTY
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Creates a new instance using an [API Access Token][accessToken].
|
* Creates a new instance using an [API Access Token][accessToken].
|
||||||
|
|
|
@ -40,5 +40,8 @@ class Constants private constructor() {
|
||||||
|
|
||||||
/** The API access token environment variable. **/
|
/** The API access token environment variable. **/
|
||||||
const val ENV_ACCESS_TOKEN = "BITLY_ACCESS_TOKEN"
|
const val ENV_ACCESS_TOKEN = "BITLY_ACCESS_TOKEN"
|
||||||
|
|
||||||
|
/** Empty String **/
|
||||||
|
const val EMPTY = ""
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -89,12 +89,8 @@ class Utils private constructor() {
|
||||||
params: Map<String, String>,
|
params: Map<String, String>,
|
||||||
method: Methods = Methods.POST
|
method: Methods = Methods.POST
|
||||||
): String {
|
): String {
|
||||||
var response = ""
|
var response = Constants.EMPTY
|
||||||
if (endPoint.isBlank()) {
|
if (validateCall(accessToken, endPoint)) {
|
||||||
logger.severe("Please specify a valid API endpoint.")
|
|
||||||
} else if (accessToken.isBlank()) {
|
|
||||||
logger.severe("Please specify a valid API access token.")
|
|
||||||
} else {
|
|
||||||
val apiUrl = endPoint.toHttpUrlOrNull()
|
val apiUrl = endPoint.toHttpUrlOrNull()
|
||||||
if (apiUrl != null) {
|
if (apiUrl != null) {
|
||||||
val builder = when (method) {
|
val builder = when (method) {
|
||||||
|
|
|
@ -60,9 +60,9 @@ class BitlyTest {
|
||||||
fun `token should be specified`() {
|
fun `token should be specified`() {
|
||||||
val test = Bitly()
|
val test = Bitly()
|
||||||
if (System.getenv("CI") == "true") {
|
if (System.getenv("CI") == "true") {
|
||||||
test.accessToken = ""
|
test.accessToken = Constants.EMPTY
|
||||||
}
|
}
|
||||||
assertEquals("", test.bitlinks().shorten(blog))
|
assertEquals(Constants.EMPTY, test.bitlinks().shorten(blog))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -73,7 +73,7 @@ class BitlyTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
fun `long url should be valid`() {
|
fun `long url should be valid`() {
|
||||||
assertEquals("", bitly.bitlinks().shorten(""))
|
assertEquals(Constants.EMPTY, bitly.bitlinks().shorten(Constants.EMPTY))
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue