Reworked PinConfig with required parameters, etc.
This commit is contained in:
parent
0f9606391e
commit
9036a32239
12 changed files with 94 additions and 57 deletions
14
README.md
14
README.md
|
@ -22,9 +22,9 @@ A small library for posting to [Pinboard](https://pinboard.in).
|
|||
|
||||
val poster = PinboardPoster("user:TOKEN")
|
||||
|
||||
poster.addPin("https://www.example.com/foo", "This is a test")
|
||||
poster.addPin("https://examples.com", "This is a test", tags = arrayOf("foo", "bar"))
|
||||
poster.deletePin("https:///www.example.com/bar")
|
||||
poster.addPin("https://example.com/foo", "This is a test")
|
||||
poster.addPin("https://example.com", "This is a test", tags = arrayOf("foo", "bar"))
|
||||
poster.deletePin("https://example.com/bar")
|
||||
|
||||
```
|
||||
|
||||
|
@ -36,13 +36,11 @@ poster.deletePin("https:///www.example.com/bar")
|
|||
|
||||
final PinboardPoster poster = new PinBboardPoster("user:TOKEN");
|
||||
|
||||
poster.addPin("https://www.example.com/foo", "This is a test");
|
||||
poster.addPin(new PinConfig.Builder()
|
||||
.url("https://example.com")
|
||||
.description("This is a test")
|
||||
poster.addPin("https://example.com/foo", "This is a test");
|
||||
poster.addPin(new PinConfig.Builder("https://example.com", "This is a test")
|
||||
.tags("foo", "bar")
|
||||
.build());
|
||||
poster.deletePin("https:///www.example.com/bar");
|
||||
poster.deletePin("https://example.com/bar");
|
||||
```
|
||||
|
||||
[View Examples](https://github.com/ethauvin/pinboard-poster/blob/master/examples)
|
||||
|
|
|
@ -1,10 +1,10 @@
|
|||
<?xml version='1.0' encoding='UTF-8'?>
|
||||
<?xml version="1.0" ?>
|
||||
<SmellBaseline>
|
||||
<ManuallySuppressedIssues/>
|
||||
<ManuallySuppressedIssues></ManuallySuppressedIssues>
|
||||
<CurrentIssues>
|
||||
<ID>LongParameterList:PinConfig.kt$PinConfig$( val url: String, val description: String, val extended: String, val tags: Array<out String>, val dt: ZonedDateTime, val replace: Boolean, val shared: Boolean, val toRead: Boolean )</ID>
|
||||
<ID>LongParameterList:PinConfig.kt$PinConfig$( var url: String, var description: String, var extended: String = "", var tags: Array<out String> = emptyArray(), var dt: ZonedDateTime = ZonedDateTime.now(), var replace: Boolean = true, var shared: Boolean = true, var toRead: Boolean = false )</ID>
|
||||
<ID>LongParameterList:PinboardPoster.kt$PinboardPoster$( url: String, description: String, extended: String = "", vararg tags: String = emptyArray(), dt: ZonedDateTime = ZonedDateTime.now(), replace: Boolean = true, shared: Boolean = true, toRead: Boolean = false )</ID>
|
||||
<ID>NestedBlockDepth:PinboardPoster.kt$PinboardPoster$private fun executeMethod(method: String, params: Map<String, String>): Boolean</ID>
|
||||
<ID>NestedBlockDepth:PinboardPoster.kt$PinboardPoster$private fun executeMethod(method: String, params: Map<String, String>): Boolean</ID>
|
||||
<ID>ThrowsCount:PinboardPoster.kt$PinboardPoster$@Throws(IOException::class) internal fun parseMethodResponse(method: String, response: String)</ID>
|
||||
<ID>TooManyFunctions:PinConfig.kt$PinConfig$Builder</ID>
|
||||
</CurrentIssues>
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
bld.downloadExtensionJavadoc=false
|
||||
bld.downloadExtensionSources=true
|
||||
bld.extensions=com.uwyn.rife2:bld-kotlin:0.9.4
|
||||
bld.extensions=com.uwyn.rife2:bld-kotlin:0.9.7
|
||||
bld.repositories=MAVEN_LOCAL,MAVEN_CENTRAL,RIFE2_SNAPSHOTS,RIFE2_RELEASES
|
||||
bld.downloadLocation=
|
||||
bld.sourceDirectories=
|
||||
|
|
|
@ -31,9 +31,7 @@ public class JavaExample {
|
|||
|
||||
if (poster.validate()) {
|
||||
// Add Pin
|
||||
if (poster.addPin(new PinConfig.Builder()
|
||||
.url(url)
|
||||
.description("Testing")
|
||||
if (poster.addPin(new PinConfig.Builder(url, "Testing")
|
||||
.extended("Extra")
|
||||
.tags("test", "java")
|
||||
.build())) {
|
||||
|
|
|
@ -19,5 +19,5 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'net.thauvin.erik:pinboard-poster:1.1.1'
|
||||
implementation 'net.thauvin.erik:pinboard-poster:1.1.2-SNAPSHOT'
|
||||
}
|
||||
|
|
|
@ -7,4 +7,4 @@
|
|||
* in the user guide at https://docs.gradle.org/4.8/userguide/multi_project_builds.html
|
||||
*/
|
||||
|
||||
rootProject.name = 'samples-java'
|
||||
rootProject.name = 'pinboard-poster-examples-gradle-java'
|
||||
|
|
|
@ -31,9 +31,7 @@ public class JavaExample {
|
|||
|
||||
if (poster.validate()) {
|
||||
// Add Pin
|
||||
if (poster.addPin(new PinConfig.Builder()
|
||||
.url(url)
|
||||
.description("Testing")
|
||||
if (poster.addPin(new PinConfig.Builder(url, "Testing")
|
||||
.extended("Extra")
|
||||
.tags("test", "java")
|
||||
.build())) {
|
||||
|
|
2
examples/gradle/kotlin/.idea/.name
generated
2
examples/gradle/kotlin/.idea/.name
generated
|
@ -1 +1 @@
|
|||
pinboard-poster-examples-gradle-kotlin
|
||||
pinboard-post-examples-gradle-kotlin
|
2
examples/gradle/kotlin/.idea/misc.xml
generated
2
examples/gradle/kotlin/.idea/misc.xml
generated
|
@ -4,5 +4,5 @@
|
|||
<component name="PDMPlugin">
|
||||
<option name="skipTestSources" value="false" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="20" project-jdk-type="JavaSDK" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="17" project-jdk-type="JavaSDK" />
|
||||
</project>
|
|
@ -1 +1 @@
|
|||
rootProject.name = "samples-kotlin"
|
||||
rootProject.name = "pinboard-post-examples-gradle-kotlin"
|
||||
|
|
|
@ -37,49 +37,86 @@ import java.time.ZonedDateTime
|
|||
* Provides a builder to add a pin.
|
||||
*
|
||||
* Supports of all the [Pinboard API Parameters](https://pinboard.in/api/#posts_add).
|
||||
*
|
||||
* @param url The URL of the bookmark.
|
||||
* @param description The title of the bookmark.
|
||||
*/
|
||||
class PinConfig private constructor(
|
||||
val url: String,
|
||||
val description: String,
|
||||
val extended: String,
|
||||
val tags: Array<out String>,
|
||||
val dt: ZonedDateTime,
|
||||
val replace: Boolean,
|
||||
val shared: Boolean,
|
||||
val toRead: Boolean
|
||||
class PinConfig @JvmOverloads constructor(
|
||||
var url: String,
|
||||
var description: String,
|
||||
var extended: String = "",
|
||||
var tags: Array<out String> = emptyArray(),
|
||||
var dt: ZonedDateTime = ZonedDateTime.now(),
|
||||
var replace: Boolean = true,
|
||||
var shared: Boolean = true,
|
||||
var toRead: Boolean = false
|
||||
) {
|
||||
constructor(builder: Builder) : this(builder.url, builder.description) {
|
||||
extended = builder.extended
|
||||
tags = builder.tags
|
||||
dt = builder.dt
|
||||
replace = builder.replace
|
||||
shared = builder.shared
|
||||
toRead = builder.toRead
|
||||
}
|
||||
/**
|
||||
* Configures the parameters to add a pin.
|
||||
*
|
||||
* @param url The URL of the bookmark.
|
||||
* @param description The title of the bookmark.
|
||||
*/
|
||||
data class Builder(
|
||||
private var url: String = "",
|
||||
private var description: String = "",
|
||||
private var extended: String = "",
|
||||
private var tags: Array<out String> = emptyArray(),
|
||||
private var dt: ZonedDateTime = ZonedDateTime.now(),
|
||||
private var replace: Boolean = true,
|
||||
private var shared: Boolean = true,
|
||||
private var toRead: Boolean = false
|
||||
) {
|
||||
data class Builder(var url: String, var description: String) {
|
||||
var extended: String = ""
|
||||
var tags: Array<out String> = emptyArray()
|
||||
var dt: ZonedDateTime = ZonedDateTime.now()
|
||||
var replace: Boolean = true
|
||||
var shared: Boolean = true
|
||||
var toRead: Boolean = false
|
||||
|
||||
/**
|
||||
* The URL of the bookmark.
|
||||
*/
|
||||
fun url(url: String) = apply { this.url = url }
|
||||
|
||||
/**
|
||||
* The title of the bookmark.
|
||||
*/
|
||||
fun description(description: String) = apply { this.description = description }
|
||||
|
||||
/**
|
||||
* The description of the bookmark.
|
||||
*/
|
||||
fun extended(extended: String) = apply { this.extended = extended }
|
||||
|
||||
/**
|
||||
* A list of up to 100 tags.
|
||||
*/
|
||||
fun tags(vararg tag: String) = apply { this.tags = tag }
|
||||
|
||||
/**
|
||||
* The creation time of the bookmark.
|
||||
*/
|
||||
fun dt(datetime: ZonedDateTime) = apply { this.dt = datetime }
|
||||
|
||||
/**
|
||||
* Replace any existing bookmark with the specified URL. Default `true`.
|
||||
*/
|
||||
fun replace(replace: Boolean) = apply { this.replace = replace }
|
||||
|
||||
/**
|
||||
* Make bookmark public. Default is `true`.
|
||||
*/
|
||||
fun shared(shared: Boolean) = apply { this.shared = shared }
|
||||
|
||||
/**
|
||||
* Mark the bookmark as unread. Default is `false`.
|
||||
*/
|
||||
fun toRead(toRead: Boolean) = apply { this.toRead = toRead }
|
||||
|
||||
fun build() = PinConfig(
|
||||
url,
|
||||
description,
|
||||
extended,
|
||||
tags,
|
||||
dt,
|
||||
replace,
|
||||
shared,
|
||||
toRead
|
||||
)
|
||||
/**
|
||||
* Builds a new comment configuration.
|
||||
*/
|
||||
fun build() = PinConfig(this)
|
||||
|
||||
override fun equals(other: Any?): Boolean {
|
||||
if (this === other) return true
|
||||
|
|
|
@ -44,11 +44,13 @@ import kotlin.test.assertFalse
|
|||
import kotlin.test.assertTrue
|
||||
|
||||
class PinboardPosterTest {
|
||||
private val url = "http://www.example.com/?random=" + (1000..10000).random()
|
||||
private val url = randomUrl()
|
||||
private val desc = "This is a test."
|
||||
private val localProps = Paths.get("local.properties")
|
||||
private val isCi = "true" == System.getenv("CI")
|
||||
|
||||
private fun randomUrl(): String = "http://www.example.com/?random=" + (1000..10000).random()
|
||||
|
||||
@Test
|
||||
fun testAddPin() {
|
||||
var poster = PinboardPoster("")
|
||||
|
@ -83,7 +85,7 @@ class PinboardPosterTest {
|
|||
|
||||
assertTrue(poster.validate(), "validate()")
|
||||
|
||||
var config = PinConfig.Builder().url(url).description(desc).extended("extra")
|
||||
var config = PinConfig.Builder(url, desc).extended("extra")
|
||||
|
||||
assertTrue(poster.addPin(config.build()), "apiToken: ${Constants.ENV_API_TOKEN}")
|
||||
|
||||
|
@ -99,13 +101,17 @@ class PinboardPosterTest {
|
|||
assertTrue(e.message!!.contains("item already exists"))
|
||||
}
|
||||
|
||||
config = config.replace(true).toRead(true)
|
||||
config = config.description("Yet another test.").replace(true).toRead(true)
|
||||
assertTrue(poster.addPin(config.build()), "toRead(true)")
|
||||
|
||||
config = config.dt(ZonedDateTime.now())
|
||||
assertTrue(poster.addPin(config.build()), "dt(now)")
|
||||
|
||||
assertTrue(poster.deletePin(url), "deletePin($url)")
|
||||
|
||||
config = config.url(randomUrl())
|
||||
assertTrue(poster.addPin(config.build()), "add($url)")
|
||||
assertTrue(poster.deletePin(config.url), "delete($url)")
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue