Implement custom bitlink update. Closes #15
This commit is contained in:
parent
55bc8d9e6a
commit
517aeb016a
10 changed files with 160 additions and 52 deletions
|
@ -61,7 +61,7 @@ public class BitlyShortenBuild extends Project {
|
|||
public BitlyShortenBuild() {
|
||||
pkg = "net.thauvin.erik";
|
||||
name = "bitly-shorten";
|
||||
version = version(1, 0, 2, "SNAPSHOT");
|
||||
version = version(2, 0, 0);
|
||||
|
||||
javaRelease = 11;
|
||||
downloadSources = true;
|
||||
|
|
|
@ -39,6 +39,8 @@ import net.thauvin.erik.bitly.config.CreateConfig
|
|||
import net.thauvin.erik.bitly.config.UpdateConfig
|
||||
import org.json.JSONException
|
||||
import org.json.JSONObject
|
||||
import java.net.URLEncoder
|
||||
import java.nio.charset.StandardCharsets
|
||||
import java.util.logging.Level
|
||||
|
||||
/**
|
||||
|
@ -301,4 +303,40 @@ open class Bitlinks(private val accessToken: String) {
|
|||
}
|
||||
return result
|
||||
}
|
||||
|
||||
/**
|
||||
* Move a keyword (or custom back-half) to a different Bitlink (domains must match).
|
||||
*
|
||||
* See the [Bit.ly API](https://dev.bitly.com/api-reference/#updateCustomBitlink) for more information.
|
||||
*
|
||||
* @param custom_bitlink A Custom Bitlink made of the domain and keyword.
|
||||
* @param toJson Returns the full JSON response if `true`.
|
||||
* @return [Constants.TRUE] if the update was successful, [Constants.FALSE] otherwise.
|
||||
*/
|
||||
@Synchronized
|
||||
@JvmOverloads
|
||||
fun updateCustom(
|
||||
custom_bitlink: String,
|
||||
bitlink_id: String,
|
||||
toJson: Boolean = false
|
||||
): String {
|
||||
var result = if (toJson) Constants.EMPTY_JSON else Constants.FALSE
|
||||
if (custom_bitlink.isNotBlank() && bitlink_id.isNotBlank()) {
|
||||
lastCallResponse = Utils.call(
|
||||
accessToken,
|
||||
"custom_bitlinks/${custom_bitlink.removeHttp()}".toEndPoint(),
|
||||
mutableMapOf<String, Any>().apply { put("bitlink_id", bitlink_id) },
|
||||
Methods.PATCH
|
||||
)
|
||||
|
||||
if (lastCallResponse.isSuccessful) {
|
||||
result = if (toJson) {
|
||||
lastCallResponse.body
|
||||
} else {
|
||||
Constants.TRUE
|
||||
}
|
||||
}
|
||||
}
|
||||
return result
|
||||
}
|
||||
}
|
||||
|
|
43
src/test/kotlin/DisableOnCi.kt
Normal file
43
src/test/kotlin/DisableOnCi.kt
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*
|
||||
* DisableOnCi.kt
|
||||
*
|
||||
* Copyright 2020-2024 Erik C. Thauvin (erik@thauvin.net)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
import org.junit.jupiter.api.extension.ExtendWith
|
||||
|
||||
/**
|
||||
* Disables tests on CI annotation.
|
||||
*
|
||||
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
|
||||
* @since 1.0
|
||||
*/
|
||||
@Target(AnnotationTarget.TYPE, AnnotationTarget.FUNCTION)
|
||||
@Retention(AnnotationRetention.RUNTIME)
|
||||
@ExtendWith(DisableOnCiCondition::class)
|
||||
annotation class DisableOnCi
|
50
src/test/kotlin/DisableOnCiCondition.kt
Normal file
50
src/test/kotlin/DisableOnCiCondition.kt
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*
|
||||
* DisableOnCiCondition.kt
|
||||
*
|
||||
* Copyright 2020-2024 Erik C. Thauvin (erik@thauvin.net)
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions are met:
|
||||
*
|
||||
* Redistributions of source code must retain the above copyright notice, this
|
||||
* list of conditions and the following disclaimer.
|
||||
*
|
||||
* Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
*
|
||||
* Neither the name of this project nor the names of its contributors may be
|
||||
* used to endorse or promote products derived from this software without
|
||||
* specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
|
||||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
|
||||
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
|
||||
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
|
||||
* CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
|
||||
* OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
|
||||
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
|
||||
*/
|
||||
|
||||
import org.junit.jupiter.api.extension.ConditionEvaluationResult
|
||||
import org.junit.jupiter.api.extension.ExecutionCondition
|
||||
import org.junit.jupiter.api.extension.ExtensionContext
|
||||
|
||||
/**
|
||||
* Disables tests on CI condition.
|
||||
*
|
||||
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
|
||||
* @since 2.0
|
||||
*/
|
||||
class DisableOnCiCondition : ExecutionCondition {
|
||||
override fun evaluateExecutionCondition(context: ExtensionContext): ConditionEvaluationResult {
|
||||
return if (System.getenv("CI") != null) {
|
||||
ConditionEvaluationResult.disabled("Test disabled on CI")
|
||||
} else {
|
||||
ConditionEvaluationResult.enabled("Test enabled")
|
||||
}
|
||||
}
|
||||
}
|
|
@ -31,6 +31,7 @@
|
|||
|
||||
package net.thauvin.erik.bitly
|
||||
|
||||
import DisableOnCi
|
||||
import assertk.all
|
||||
import assertk.assertThat
|
||||
import assertk.assertions.*
|
||||
|
@ -227,6 +228,16 @@ class BitlyTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@DisableOnCi
|
||||
fun `update custom bitlink`() {
|
||||
val bl = bitly.bitlinks()
|
||||
assertEquals(
|
||||
Constants.TRUE,
|
||||
bl.updateCustom("https://thauv.in/2NwtljT", "thauv.in/2NwtljT")
|
||||
)
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `update bitlink`() {
|
||||
val bl = bitly.bitlinks()
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue