Added update config builder. Closes #8
This commit is contained in:
parent
82d31578c8
commit
31f5aac584
7 changed files with 225 additions and 4 deletions
5
.idea/jarRepositories.xml
generated
5
.idea/jarRepositories.xml
generated
|
@ -46,5 +46,10 @@
|
|||
<option name="name" value="maven" />
|
||||
<option name="url" value="https://packages.jetbrains.team/maven/p/ij/intellij-dependencies" />
|
||||
</remote-repository>
|
||||
<remote-repository>
|
||||
<option name="id" value="MavenLocal" />
|
||||
<option name="name" value="MavenLocal" />
|
||||
<option name="url" value="file:$PROJECT_DIR$/../../maven/repository/" />
|
||||
</remote-repository>
|
||||
</component>
|
||||
</project>
|
|
@ -5,13 +5,13 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|||
import java.net.URL
|
||||
|
||||
plugins {
|
||||
id("com.github.ben-manes.versions") version "0.42.0"
|
||||
id("com.github.ben-manes.versions") version "0.43.0"
|
||||
id("io.gitlab.arturbosch.detekt") version "1.21.0"
|
||||
id("java")
|
||||
id("java-library")
|
||||
id("maven-publish")
|
||||
id("net.thauvin.erik.gradle.semver") version "1.0.4"
|
||||
id("org.jetbrains.dokka") version "1.7.10"
|
||||
id("org.jetbrains.dokka") version "1.7.20"
|
||||
id("org.jetbrains.kotlinx.kover") version "0.6.1"
|
||||
id("org.sonarqube") version "3.4.0.2513"
|
||||
id("signing")
|
||||
|
@ -57,7 +57,6 @@ dependencies {
|
|||
testImplementation(kotlin("test"))
|
||||
testImplementation(kotlin("test-junit"))
|
||||
testImplementation("com.willowtreeapps.assertk:assertk-jvm:0.25")
|
||||
|
||||
}
|
||||
|
||||
kapt {
|
||||
|
|
|
@ -3,6 +3,17 @@
|
|||
<ManuallySuppressedIssues/>
|
||||
<CurrentIssues>
|
||||
<ID>ComplexMethod:Bitlinks.kt$Bitlinks$@Synchronized @JvmOverloads 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>ComplexMethod:UpdateConfig.kt$UpdateConfig.Builder$override fun equals(other: Any?): Boolean</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$var client_id: String = Constants.EMPTY</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig.Builder$var created_at: String = Constants.EMPTY</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig.Builder$var created_by: String = Constants.EMPTY</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig.Builder$var custom_bitlinks: Array<String> = emptyArray()</ID>
|
||||
<ID>ConstructorParameterNaming:UpdateConfig.kt$UpdateConfig.Builder$var long_url: String = Constants.EMPTY</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>
|
||||
|
@ -12,9 +23,15 @@
|
|||
<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:UpdateConfig.kt$UpdateConfig.Builder$client_id: String</ID>
|
||||
<ID>FunctionParameterNaming:UpdateConfig.kt$UpdateConfig.Builder$created_at: String</ID>
|
||||
<ID>FunctionParameterNaming:UpdateConfig.kt$UpdateConfig.Builder$created_by: String</ID>
|
||||
<ID>FunctionParameterNaming:UpdateConfig.kt$UpdateConfig.Builder$custom_bitlinks: Array<String></ID>
|
||||
<ID>FunctionParameterNaming:UpdateConfig.kt$UpdateConfig.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: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>MagicNumber:CallResponse.kt$CallResponse$200</ID>
|
||||
<ID>MagicNumber:CallResponse.kt$CallResponse$201</ID>
|
||||
<ID>MagicNumber:CallResponse.kt$CallResponse$299</ID>
|
||||
|
@ -29,6 +46,7 @@
|
|||
<ID>NestedBlockDepth:Bitlinks.kt$Bitlinks$private fun parseJsonResponse(response: CallResponse, key: String, default: String, toJson: Boolean): String</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>TooManyFunctions:UpdateConfig.kt$UpdateConfig$Builder</ID>
|
||||
<ID>UtilityClassWithPublicConstructor:Constants.kt$Constants</ID>
|
||||
<ID>UtilityClassWithPublicConstructor:Utils.kt$Utils</ID>
|
||||
</CurrentIssues>
|
||||
|
|
|
@ -2,7 +2,7 @@ import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
|
|||
|
||||
plugins {
|
||||
id("application")
|
||||
id("com.github.ben-manes.versions") version "0.42.0"
|
||||
id("com.github.ben-manes.versions") version "0.43.0"
|
||||
kotlin("jvm") version "1.7.20"
|
||||
}
|
||||
|
||||
|
|
|
@ -222,6 +222,35 @@ open class Bitlinks(private val accessToken: String) {
|
|||
return bitlink
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Updates fields in the specified Bitlink.
|
||||
*
|
||||
* See the [Bit.ly API](https://dev.bitly.com/api-reference#updateBitlink) for more information.
|
||||
*
|
||||
* @param config The update configuration.
|
||||
* @return [Constants.TRUE] if the update was successful, [Constants.FALSE] otherwise.
|
||||
*/
|
||||
@Synchronized
|
||||
fun update(config: UpdateConfig): String {
|
||||
return update(
|
||||
config.bitlink,
|
||||
config.references,
|
||||
config.archived,
|
||||
config.tags,
|
||||
config.created_at,
|
||||
config.title,
|
||||
config.deepLinks,
|
||||
config.created_by,
|
||||
config.long_url,
|
||||
config.client_id,
|
||||
config.custom_bitlinks,
|
||||
config.link,
|
||||
config.id,
|
||||
config.toJson
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates fields in the specified Bitlink.
|
||||
*
|
||||
|
|
142
src/main/kotlin/net/thauvin/erik/bitly/UpdateConfig.kt
Normal file
142
src/main/kotlin/net/thauvin/erik/bitly/UpdateConfig.kt
Normal file
|
@ -0,0 +1,142 @@
|
|||
/*
|
||||
* UpdateConfig.kt
|
||||
*
|
||||
* Copyright (c) 2020-2022, Erik C. Thauvin (erik@thauvin.net)
|
||||
* All rights reserved.
|
||||
*
|
||||
* 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.
|
||||
*/
|
||||
|
||||
package net.thauvin.erik.bitly
|
||||
|
||||
class UpdateConfig private constructor(
|
||||
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,
|
||||
) {
|
||||
@Suppress("unused")
|
||||
data class Builder(
|
||||
var bitlink: String = Constants.EMPTY,
|
||||
var references: Map<String, String> = emptyMap(),
|
||||
var archived: Boolean = false,
|
||||
var tags: Array<String> = emptyArray(),
|
||||
var created_at: String = Constants.EMPTY,
|
||||
var title: String = Constants.EMPTY,
|
||||
var deeplinks: Array<Map<String, String>> = emptyArray(),
|
||||
var created_by: String = Constants.EMPTY,
|
||||
var long_url: String = Constants.EMPTY,
|
||||
var client_id: String = Constants.EMPTY,
|
||||
var custom_bitlinks: Array<String> = emptyArray(),
|
||||
var link: String = Constants.EMPTY,
|
||||
var id: String = Constants.EMPTY,
|
||||
var toJson: Boolean = false
|
||||
) {
|
||||
fun bitlink(bitlink: String) = apply { this.bitlink = bitlink }
|
||||
fun references(references: Map<String, String>) = apply { this.references = references }
|
||||
fun archived(archived: Boolean) = apply { this.archived = archived }
|
||||
fun tags(tags: Array<String>) = apply { this.tags = tags }
|
||||
fun createdAt(created_at: String) = apply { this.created_at = created_at }
|
||||
fun title(title: String) = apply { this.title = title }
|
||||
fun deeplinks(deeplinks: Array<Map<String, String>>) = apply { this.deeplinks = deeplinks }
|
||||
fun createdBy(created_by: String) = apply { this.created_by = created_by }
|
||||
fun longUrl(long_url: String) = apply { this.long_url = long_url }
|
||||
fun clientId(client_id: String) = apply { this.client_id = client_id }
|
||||
fun customBitlinks(custom_bitlinks: Array<String>) = apply { this.custom_bitlinks = custom_bitlinks }
|
||||
fun link(link: String) = apply { this.link = link }
|
||||
fun id(id: String) = apply { this.id = id }
|
||||
fun toJson(toJson: Boolean) = apply { this.toJson = toJson }
|
||||
|
||||
fun build() = UpdateConfig(
|
||||
bitlink,
|
||||
references,
|
||||
archived,
|
||||
tags,
|
||||
created_at,
|
||||
title,
|
||||
deeplinks,
|
||||
created_by,
|
||||
long_url,
|
||||
client_id,
|
||||
custom_bitlinks,
|
||||
link,
|
||||
id,
|
||||
toJson
|
||||
)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
if (javaClass != other?.javaClass) return false
|
||||
|
||||
other as Builder
|
||||
|
||||
if (bitlink != other.bitlink) return false
|
||||
if (references != other.references) return false
|
||||
if (archived != other.archived) return false
|
||||
if (!tags.contentEquals(other.tags)) return false
|
||||
if (created_at != other.created_at) return false
|
||||
if (title != other.title) return false
|
||||
if (!deeplinks.contentEquals(other.deeplinks)) return false
|
||||
if (created_by != other.created_by) return false
|
||||
if (long_url != other.long_url) return false
|
||||
if (client_id != other.client_id) return false
|
||||
if (!custom_bitlinks.contentEquals(other.custom_bitlinks)) return false
|
||||
if (link != other.link) return false
|
||||
if (id != other.id) return false
|
||||
if (toJson != other.toJson) return false
|
||||
|
||||
return true
|
||||
}
|
||||
|
||||
override fun hashCode(): Int {
|
||||
var result = bitlink.hashCode()
|
||||
result = 31 * result + references.hashCode()
|
||||
result = 31 * result + archived.hashCode()
|
||||
result = 31 * result + tags.contentHashCode()
|
||||
result = 31 * result + created_at.hashCode()
|
||||
result = 31 * result + title.hashCode()
|
||||
result = 31 * result + deeplinks.contentHashCode()
|
||||
result = 31 * result + created_by.hashCode()
|
||||
result = 31 * result + long_url.hashCode()
|
||||
result = 31 * result + client_id.hashCode()
|
||||
result = 31 * result + custom_bitlinks.contentHashCode()
|
||||
result = 31 * result + link.hashCode()
|
||||
result = 31 * result + id.hashCode()
|
||||
result = 31 * result + toJson.hashCode()
|
||||
return result
|
||||
}
|
||||
}
|
||||
}
|
|
@ -200,6 +200,34 @@ class BitlyTest {
|
|||
assertThat(bl.lastCallResponse).prop(CallResponse::isUnprocessableEntity).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `update bitlink with config`() {
|
||||
val bl = bitly.bitlinks()
|
||||
var config = UpdateConfig.Builder().apply {
|
||||
bitlink(shortUrl)
|
||||
title("Erik's Weblog")
|
||||
tags(arrayOf("blog", "weblog"))
|
||||
archived(true)
|
||||
}.build()
|
||||
|
||||
assertEquals(Constants.TRUE, bl.update(config))
|
||||
|
||||
config = UpdateConfig.Builder().apply {
|
||||
bitlink(shortUrl)
|
||||
toJson(true)
|
||||
}.build()
|
||||
|
||||
assertThat(bl.update(config), "update(tags)").contains("\"tags\":[]")
|
||||
|
||||
config = UpdateConfig.Builder().apply {
|
||||
bitlink(shortUrl)
|
||||
link(longUrl)
|
||||
}.build()
|
||||
bl.update(config)
|
||||
|
||||
assertThat(bl.lastCallResponse).prop(CallResponse::isUnprocessableEntity).isTrue()
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `validate URL`() {
|
||||
assertTrue("https://www.example.com".isValidUrl(), "valid url")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue