Made validate function public
This commit is contained in:
parent
8c3687591d
commit
5128916fa1
13 changed files with 70 additions and 48 deletions
|
@ -124,6 +124,7 @@ The library used [`java.util.logging`](https://docs.oracle.com/javase/8/docs/api
|
|||
with(poster.logger) {
|
||||
addHandler(ConsoleHandler().apply { level = Level.FINE })
|
||||
level = Level.FINE
|
||||
useParentHandlers = false
|
||||
}
|
||||
```
|
||||
|
||||
|
@ -135,6 +136,7 @@ consoleHandler.setLevel(Level.FINE);
|
|||
final Logger logger = poster.getLogger();
|
||||
logger.addHandler(consoleHandler);
|
||||
logger.setLevel(Level.FINE);
|
||||
logger.setUseParentHandlers(false);
|
||||
```
|
||||
|
||||
or using a logging properties file.
|
||||
|
|
1
examples/bld/.idea/app.iml
generated
1
examples/bld/.idea/app.iml
generated
|
@ -10,6 +10,7 @@
|
|||
<sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/resources" type="java-test-resource" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/test/kotlin" isTestSource="true" />
|
||||
<sourceFolder url="file://$MODULE_DIR$/src/main/kotlin" isTestSource="false" />
|
||||
</content>
|
||||
<orderEntry type="inheritedJdk" />
|
||||
<orderEntry type="sourceFolder" forTests="false" />
|
||||
|
|
2
examples/bld/.idea/misc.xml
generated
2
examples/bld/.idea/misc.xml
generated
|
@ -6,4 +6,4 @@
|
|||
<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>
|
||||
|
|
|
@ -29,19 +29,21 @@ public class JavaExample {
|
|||
logger.setLevel(Level.FINE);
|
||||
logger.setUseParentHandlers(false);
|
||||
|
||||
// Add Pin
|
||||
if (poster.addPin(new PinConfig.Builder()
|
||||
.url(url)
|
||||
.description("Testing")
|
||||
.extended("Extra")
|
||||
.tags("test", "java")
|
||||
.build())) {
|
||||
System.out.println("Added: " + url);
|
||||
}
|
||||
if (poster.validate()) {
|
||||
// Add Pin
|
||||
if (poster.addPin(new PinConfig.Builder()
|
||||
.url(url)
|
||||
.description("Testing")
|
||||
.extended("Extra")
|
||||
.tags("test", "java")
|
||||
.build())) {
|
||||
System.out.println("Added: " + url);
|
||||
}
|
||||
|
||||
// Delete Pin
|
||||
if (poster.deletePin(url)) {
|
||||
System.out.println("Deleted: " + url);
|
||||
// Delete Pin
|
||||
if (poster.deletePin(url)) {
|
||||
System.out.println("Deleted: " + url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,15 +20,18 @@ fun main(args: Array<String>) {
|
|||
with(poster.logger) {
|
||||
addHandler(ConsoleHandler().apply { level = Level.FINE })
|
||||
level = Level.FINE
|
||||
useParentHandlers = false
|
||||
}
|
||||
|
||||
// Add Pin
|
||||
if (poster.addPin(url, "Testing", "Extended test", tags = arrayOf("test", "kotlin"))) {
|
||||
println("Added: $url")
|
||||
}
|
||||
if (poster.validate()) {
|
||||
// Add Pin
|
||||
if (poster.addPin(url, "Testing", "Extended test", tags = arrayOf("test", "kotlin"))) {
|
||||
println("Added: $url")
|
||||
}
|
||||
|
||||
// Delete Pin
|
||||
if (poster.deletePin(url)) {
|
||||
println("Deleted: $url")
|
||||
// Delete Pin
|
||||
if (poster.deletePin(url)) {
|
||||
println("Deleted: $url")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
2
examples/gradle/java/.idea/misc.xml
generated
2
examples/gradle/java/.idea/misc.xml
generated
|
@ -5,4 +5,4 @@
|
|||
<option name="skipTestSources" value="false" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="20" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
@ -29,19 +29,21 @@ public class JavaExample {
|
|||
logger.setLevel(Level.FINE);
|
||||
logger.setUseParentHandlers(false);
|
||||
|
||||
// Add Pin
|
||||
if (poster.addPin(new PinConfig.Builder()
|
||||
.url(url)
|
||||
.description("Testing")
|
||||
.extended("Extra")
|
||||
.tags("test", "java")
|
||||
.build())) {
|
||||
System.out.println("Added: " + url);
|
||||
}
|
||||
if (poster.validate()) {
|
||||
// Add Pin
|
||||
if (poster.addPin(new PinConfig.Builder()
|
||||
.url(url)
|
||||
.description("Testing")
|
||||
.extended("Extra")
|
||||
.tags("test", "java")
|
||||
.build())) {
|
||||
System.out.println("Added: " + url);
|
||||
}
|
||||
|
||||
// Delete Pin
|
||||
if (poster.deletePin(url)) {
|
||||
System.out.println("Deleted: " + url);
|
||||
// Delete Pin
|
||||
if (poster.deletePin(url)) {
|
||||
System.out.println("Deleted: " + url);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
2
examples/gradle/kotlin/.idea/misc.xml
generated
2
examples/gradle/kotlin/.idea/misc.xml
generated
|
@ -5,4 +5,4 @@
|
|||
<option name="skipTestSources" value="false" />
|
||||
</component>
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_11" project-jdk-name="20" project-jdk-type="JavaSDK" />
|
||||
</project>
|
||||
</project>
|
||||
|
|
|
@ -20,15 +20,18 @@ fun main(args: Array<String>) {
|
|||
with(poster.logger) {
|
||||
addHandler(ConsoleHandler().apply { level = Level.FINE })
|
||||
level = Level.FINE
|
||||
useParentHandlers = false
|
||||
}
|
||||
|
||||
// Add Pin
|
||||
if (poster.addPin(url, "Testing", "Extended test", tags = arrayOf("test", "kotlin"))) {
|
||||
println("Added: $url")
|
||||
}
|
||||
if (poster.validate()) {
|
||||
// Add Pin
|
||||
if (poster.addPin(url, "Testing", "Extended test", tags = arrayOf("test", "kotlin"))) {
|
||||
println("Added: $url")
|
||||
}
|
||||
|
||||
// Delete Pin
|
||||
if (poster.deletePin(url)) {
|
||||
println("Deleted: $url")
|
||||
// Delete Pin
|
||||
if (poster.deletePin(url)) {
|
||||
println("Deleted: $url")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -55,7 +55,7 @@ import static rife.bld.dependencies.Scope.test;
|
|||
|
||||
public class PinboardPosterBuild extends Project {
|
||||
public PinboardPosterBuild() {
|
||||
pkg = "net.thauvin.erik.pinboard";
|
||||
pkg = "net.thauvin.erik";
|
||||
name = "pinboard-poster";
|
||||
version = version(1, 1, 1, "SNAPSHOT");
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class PinboardPosterBuild extends Project {
|
|||
: repository(SONATYPE_RELEASES_LEGACY.location())
|
||||
.withCredentials(property("sonatype.user"), property("sonatype.password")))
|
||||
.info()
|
||||
.groupId("net.thauvin.erik")
|
||||
.groupId(pkg)
|
||||
.artifactId(name)
|
||||
.description("A small library for posting to Pinboard")
|
||||
.url("https://github.com/ethauvin/" + name)
|
||||
|
|
|
@ -35,6 +35,8 @@ import java.time.ZonedDateTime
|
|||
|
||||
/**
|
||||
* Provides a builder to add a pin.
|
||||
*
|
||||
* Supports of all the [Pinboard API Parameters](https://pinboard.in/api/#posts_add).
|
||||
*/
|
||||
class PinConfig private constructor(
|
||||
val url: String,
|
||||
|
|
|
@ -65,7 +65,7 @@ object Constants {
|
|||
*
|
||||
* @constructor Creates a new instance.
|
||||
*
|
||||
* @author [Erik C. Thauvin](https://erik.thauvin.net/)
|
||||
* @author <a href="https://erik.thauvin.net/">Erik C. Thauvin</a>
|
||||
*/
|
||||
open class PinboardPoster() {
|
||||
/**
|
||||
|
@ -135,9 +135,7 @@ open class PinboardPoster() {
|
|||
}
|
||||
|
||||
/**
|
||||
* Adds a bookmark to Pinboard
|
||||
*
|
||||
* This method supports of all the [Pinboard API Parameters](https://pinboard.in/api/#posts_add).
|
||||
* Adds a bookmark to Pinboard using a [PinConfig] builder.
|
||||
*/
|
||||
fun addPin(config: PinConfig): Boolean {
|
||||
return addPin(
|
||||
|
@ -293,7 +291,10 @@ open class PinboardPoster() {
|
|||
return false
|
||||
}
|
||||
|
||||
private fun validate(): Boolean {
|
||||
/**
|
||||
* Ensures that the API token and end point are valid.
|
||||
*/
|
||||
fun validate(): Boolean {
|
||||
var isValid = true
|
||||
if (!apiToken.contains(':')) {
|
||||
logger.severe("Please specify a valid API token. (eg. user:TOKEN)")
|
||||
|
|
|
@ -66,6 +66,8 @@ class PinboardPosterTest {
|
|||
if (!isCi) {
|
||||
poster.logger.level = Level.FINE
|
||||
}
|
||||
assertTrue(poster.validate(), "validate()")
|
||||
|
||||
assertTrue(poster.addPin(url, desc), "addPin($url, $desc)")
|
||||
|
||||
assertTrue(poster.deletePin(url), "deletePin($url)")
|
||||
|
@ -78,6 +80,8 @@ class PinboardPosterTest {
|
|||
poster.logger.level = Level.FINE
|
||||
}
|
||||
|
||||
assertTrue(poster.validate(), "validate()")
|
||||
|
||||
var config = PinConfig.Builder().url(url).description(desc).extended("extra")
|
||||
|
||||
assertTrue(poster.addPin(config.build()), "apiToken: ${Constants.ENV_API_TOKEN}")
|
||||
|
@ -120,6 +124,8 @@ class PinboardPosterTest {
|
|||
poster.logger.level = Level.FINE
|
||||
}
|
||||
|
||||
assertTrue(poster.validate(), "validate()")
|
||||
|
||||
poster.apiEndPoint = ""
|
||||
assertFalse(poster.deletePin(url), "apiEndPoint: <blank>")
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue