Implement custom bitlink update. Closes #15
This commit is contained in:
parent
55bc8d9e6a
commit
517aeb016a
10 changed files with 160 additions and 52 deletions
16
.idea/misc.xml
generated
16
.idea/misc.xml
generated
|
@ -8,21 +8,7 @@
|
|||
<pattern value="net.thauvin.erik.bitly.BitlyShortenBuild" method="detekt" />
|
||||
<pattern value="net.thauvin.erik.bitly.BitlyShortenBuild" method="detektBaseline" />
|
||||
</component>
|
||||
<component name="PDMPlugin">
|
||||
<option name="customRuleSets">
|
||||
<list>
|
||||
<option value="K:\java\semver\config\pmd.xml" />
|
||||
<option value="$PROJECT_DIR$/../../java/bld-pitest/config/pmd.xml" />
|
||||
<option value="$PROJECT_DIR$/../../java/bld-jacoco-report/config/pmd.xml" />
|
||||
<option value="$PROJECT_DIR$/../../java/bld-checkstyle/config/pmd.xml" />
|
||||
<option value="$PROJECT_DIR$/../../java/bld-exec/config/pmd.xml" />
|
||||
<option value="$PROJECT_DIR$/../../java/bld-testng/config/pmd.xml" />
|
||||
<option value="$PROJECT_DIR$/../../java/bld-generated-version/config/pmd.xml" />
|
||||
</list>
|
||||
</option>
|
||||
<option name="skipTestSources" value="false" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_17" project-jdk-name="17" project-jdk-type="JavaSDK">
|
||||
<output url="file://$PROJECT_DIR$/build" />
|
||||
</component>
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
@ -90,18 +90,16 @@ Instructions for using with Maven, Ivy, etc. can be found on [Maven Central](htt
|
|||
To make it easier to use the library with Java, configuration builders are available:
|
||||
|
||||
```java
|
||||
var config = new CreateConfig.Builder()
|
||||
var config = new CreateConfig.Builder("https://erik.thauvin.net/blog")
|
||||
.title("Erik's Weblog")
|
||||
.tags(new String[] { "blog", "weblog"})
|
||||
.longUrl("https://erik.thauvin.net/blog")
|
||||
.build();
|
||||
|
||||
bitly.bitlinks().create(config);
|
||||
```
|
||||
|
||||
```java
|
||||
var config = new UpdateConfig.Builder()
|
||||
.bitlink("https://bit.ly/380ojFd")
|
||||
var config = new UpdateConfig.Builder("https://bit.ly/380ojFd")
|
||||
.title("Erik's Weblog")
|
||||
.tags(new String[] { "blog", "weblog"})
|
||||
.build();
|
||||
|
@ -171,7 +169,7 @@ if (response.isSuccessful) {
|
|||
}
|
||||
```
|
||||
|
||||
- View [Example](https://github.com/ethauvin/bitly-shorten/blob/master/examples/src/main/kotlin/com/example/BitlyRetrieve.kt)
|
||||
- View [Example](https://github.com/ethauvin/bitly-shorten/blob/master/examples/bld/src/main/kotlin/com/example/BitlyRetrieve.kt)
|
||||
|
||||
## Contributing
|
||||
|
||||
|
|
|
@ -1,38 +1,17 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<?xml version="1.0" ?>
|
||||
<SmellBaseline>
|
||||
<ManuallySuppressedIssues/>
|
||||
<ManuallySuppressedIssues></ManuallySuppressedIssues>
|
||||
<CurrentIssues>
|
||||
<ID>ConstructorParameterNaming:CreateConfig.kt$CreateConfig$val group_guid: String</ID>
|
||||
<ID>ConstructorParameterNaming:CreateConfig.kt$CreateConfig$val long_url: String</ID>
|
||||
<ID>ConstructorParameterNaming:CreateConfig.kt$CreateConfig.Builder$private var group_guid: String = Constants.EMPTY</ID>
|
||||
<ID>ConstructorParameterNaming:CreateConfig.kt$CreateConfig.Builder$private var long_url: String = Constants.EMPTY</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig$val client_id: String</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig$val created_at: String</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig$val created_by: String</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig$val custom_bitlinks: Array<String></ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig$val long_url: String</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig.Builder$private var client_id: String = Constants.EMPTY</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig.Builder$private var created_at: String = Constants.EMPTY</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig.Builder$private var created_by: String = Constants.EMPTY</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig.Builder$private var custom_bitlinks: Array<String> = emptyArray()</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig.Builder$private var long_url: String = Constants.EMPTY</ID>
|
||||
<ID>CyclomaticComplexMethod:Bitlinks.kt$Bitlinks$@Synchronized fun update( bitlink: String, references: Map<String, String> = emptyMap(), archived: Boolean = false, tags: Array<String> = emptyArray(), created_at: String = Constants.EMPTY, title: String = Constants.EMPTY, deeplinks: Array<Map<String, String>> = emptyArray(), created_by: String = Constants.EMPTY, long_url: String = Constants.EMPTY, client_id: String = Constants.EMPTY, custom_bitlinks: Array<String> = emptyArray(), link: String = Constants.EMPTY, id: String = Constants.EMPTY, toJson: Boolean = false ): String</ID>
|
||||
<ID>ConstructorParameterNaming:CreateConfig.kt$CreateConfig.Builder$var long_url: String</ID>
|
||||
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$bitlink_id: String</ID>
|
||||
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$client_id: String = Constants.EMPTY</ID>
|
||||
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$created_at: String = Constants.EMPTY</ID>
|
||||
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$created_by: String = Constants.EMPTY</ID>
|
||||
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$custom_bitlinks: Array<String> = emptyArray()</ID>
|
||||
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$custom_bitlink: 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 = Constants.EMPTY</ID>
|
||||
<ID>FunctionParameterNaming:Bitlinks.kt$Bitlinks$unit_reference: String = Constants.EMPTY</ID>
|
||||
<ID>FunctionParameterNaming:CreateConfig.kt$CreateConfig.Builder$group_guid: String</ID>
|
||||
<ID>FunctionParameterNaming:CreateConfig.kt$CreateConfig.Builder$long_url: String</ID>
|
||||
<ID>LongParameterList:Bitlinks.kt$Bitlinks$( bitlink: String, references: Map<String, String> = emptyMap(), archived: Boolean = false, tags: Array<String> = emptyArray(), created_at: String = Constants.EMPTY, title: String = Constants.EMPTY, deeplinks: Array<Map<String, String>> = emptyArray(), created_by: String = Constants.EMPTY, long_url: String = Constants.EMPTY, client_id: String = Constants.EMPTY, custom_bitlinks: Array<String> = emptyArray(), link: String = Constants.EMPTY, id: String = Constants.EMPTY, toJson: Boolean = false )</ID>
|
||||
<ID>LongParameterList:Bitlinks.kt$Bitlinks$( bitlink: String, unit: Units = Units.DAY, units: Int = -1, size: Int = 50, unit_reference: String = Constants.EMPTY, toJson: Boolean = false )</ID>
|
||||
<ID>LongParameterList:Bitlinks.kt$Bitlinks$( domain: String = Constants.EMPTY, title: String = Constants.EMPTY, group_guid: String = Constants.EMPTY, tags: Array<String> = emptyArray(), deeplinks: Array<Map<String, String>> = emptyArray(), long_url: String, toJson: Boolean = false )</ID>
|
||||
<ID>LongParameterList:CreateConfig.kt$CreateConfig$( val domain: String, val title: String, val group_guid: String, val tags: Array<String>, val deepLinks: Array<Map<String, String>>, val long_url: String, val toJson: Boolean )</ID>
|
||||
<ID>LongParameterList:UpdateConfig.kt$UpdateConfig$( val bitlink: String, val references: Map<String, String>, val archived: Boolean, val tags: Array<String>, val created_at: String, val title: String, val deepLinks: Array<Map<String, String>>, val created_by: String, val long_url: String, val client_id: String, val custom_bitlinks: Array<String>, val link: String, val id: String, val toJson: Boolean, )</ID>
|
||||
<ID>LongParameterList:Bitlinks.kt$Bitlinks$( bitlink: String, title: String = Constants.EMPTY, archived: Boolean = false, tags: Array<String> = emptyArray(), deeplinks: Array<Map<String, String>> = emptyArray(), toJson: Boolean = false )</ID>
|
||||
<ID>LongParameterList:Bitlinks.kt$Bitlinks$( long_url: String, domain: String = Constants.EMPTY, group_guid: String = Constants.EMPTY, title: String = Constants.EMPTY, tags: Array<String> = emptyArray(), deeplinks: Array<Map<String, String>> = emptyArray(), toJson: Boolean = false )</ID>
|
||||
<ID>MagicNumber:CallResponse.kt$CallResponse$200</ID>
|
||||
<ID>MagicNumber:CallResponse.kt$CallResponse$201</ID>
|
||||
<ID>MagicNumber:CallResponse.kt$CallResponse$299</ID>
|
||||
|
@ -47,9 +26,12 @@
|
|||
<ID>MagicNumber:CallResponse.kt$CallResponse$500</ID>
|
||||
<ID>MagicNumber:CallResponse.kt$CallResponse$503</ID>
|
||||
<ID>NestedBlockDepth:Bitlinks.kt$Bitlinks$private fun parseJsonResponse(response: CallResponse, key: String, default: String, toJson: Boolean): String</ID>
|
||||
<ID>NestedBlockDepth:Utils.kt$Utils$@JvmStatic @JvmOverloads fun call( accessToken: String, endPoint: String, params: Map<String, Any> = emptyMap(), method: Methods = Methods.POST ): CallResponse</ID>
|
||||
<ID>NestedBlockDepth:BitlyExample.kt$fun main(args: Array<String>)</ID>
|
||||
<ID>NestedBlockDepth:Utils.kt$Utils$@JvmStatic @JvmOverloads fun call( accessToken: String, endPoint: String, params: Map<String, Any> = emptyMap(), method: Methods = Methods.POST ): CallResponse</ID>
|
||||
<ID>NestedBlockDepth:Utils.kt$Utils$private fun parseResponse(response: Response, endPoint: String): CallResponse</ID>
|
||||
<ID>TooManyFunctions:UpdateConfig.kt$UpdateConfig$Builder</ID>
|
||||
<ID>VariableNaming:CreateConfig.kt$CreateConfig$val group_guid: String</ID>
|
||||
<ID>VariableNaming:CreateConfig.kt$CreateConfig$val long_url: String</ID>
|
||||
<ID>VariableNaming:CreateConfig.kt$CreateConfig.Builder$var group_guid: String = Constants.EMPTY</ID>
|
||||
<ID>WildcardImport:BitlyTest.kt$import assertk.assertions.*</ID>
|
||||
<ID>WildcardImport:BitlyTest.kt$import kotlin.test.*</ID>
|
||||
</CurrentIssues>
|
||||
|
|
|
@ -24,7 +24,7 @@ public class ExampleBuild extends BaseProject {
|
|||
repositories = List.of(MAVEN_LOCAL, MAVEN_CENTRAL, SONATYPE_SNAPSHOTS_LEGACY);
|
||||
|
||||
scope(compile)
|
||||
.include(dependency("net.thauvin.erik:bitly-shorten:1.0.2-SNAPSHOT"))
|
||||
.include(dependency("net.thauvin.erik:bitly-shorten:2.0.0"))
|
||||
.include(dependency("org.json:json:20240303"));
|
||||
}
|
||||
|
||||
|
|
|
@ -17,7 +17,7 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation("net.thauvin.erik:bitly-shorten:1.0.1")
|
||||
implementation("net.thauvin.erik:bitly-shorten:2.0.0")
|
||||
implementation("org.json:json:20240303")
|
||||
}
|
||||
|
||||
|
|
|
@ -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