Made builder fields private
This commit is contained in:
parent
ca6ac25013
commit
f6f3c82513
4 changed files with 21 additions and 19 deletions
|
@ -81,9 +81,9 @@ To make it easier to use the library with Java, configuration builders are avail
|
|||
```java
|
||||
var config = new Config.Builder()
|
||||
.url("https://www.example.com/")
|
||||
.shorturl("foobar")
|
||||
.shortUrl("foobar")
|
||||
.callback("test")
|
||||
.logstats(true)
|
||||
.logStats(true)
|
||||
.format(Format.JSON)
|
||||
.build();
|
||||
|
||||
|
|
|
@ -12,7 +12,7 @@ public final class IsgdSample {
|
|||
try {
|
||||
if (arg.contains("is.gd")) {
|
||||
System.out.println(arg + " <-- " + Isgd.lookup(arg));
|
||||
System.out.print(Isgd.lookup(new Config.Builder().shorturl(arg).format(Format.WEB).build()));
|
||||
System.out.print(Isgd.lookup(new Config.Builder().shortUrl(arg).format(Format.WEB).build()));
|
||||
} else {
|
||||
System.out.println(arg + " --> " + Isgd.shorten(arg));
|
||||
}
|
||||
|
|
|
@ -44,19 +44,21 @@ class Config private constructor(
|
|||
) {
|
||||
/**
|
||||
* Configures the parameters to create/lookup an is.gd shortlink.
|
||||
*
|
||||
* See the [is.gd API](https://is.gd/apishorteningreference.php).
|
||||
*/
|
||||
data class Builder(
|
||||
var url: String = "",
|
||||
var shorturl: String = "",
|
||||
var callback: String = "",
|
||||
var logstats: Boolean = false,
|
||||
var format: Format = Format.SIMPLE,
|
||||
var isVgd: Boolean = false
|
||||
private var url: String = "",
|
||||
private var shorturl: String = "",
|
||||
private var callback: String = "",
|
||||
private var logstats: Boolean = false,
|
||||
private var format: Format = Format.SIMPLE,
|
||||
private var isVgd: Boolean = false
|
||||
) {
|
||||
fun url(url: String) = apply { this.url = url }
|
||||
fun shorturl(shorturl: String) = apply { this.shorturl = shorturl }
|
||||
fun shortUrl(shortUrl: String) = apply { this.shorturl = shortUrl }
|
||||
fun callback(callback: String) = apply { this.callback = callback }
|
||||
fun logstats(logstats: Boolean) = apply { this.logstats = logstats }
|
||||
fun logStats(logStats: Boolean) = apply { this.logstats = logStats }
|
||||
fun format(format: Format) = apply { this.format = format }
|
||||
fun isVgd(isVgd: Boolean) = apply { this.isVgd = isVgd }
|
||||
|
||||
|
|
|
@ -84,7 +84,7 @@ class IsgdTest {
|
|||
assertFailsWith(
|
||||
message = "lookup(config:empty)",
|
||||
exceptionClass = IllegalArgumentException::class,
|
||||
block = { Isgd.lookup(Config.Builder().shorturl("").build()) }
|
||||
block = { Isgd.lookup(Config.Builder().shortUrl("").build()) }
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -96,10 +96,10 @@ class IsgdTest {
|
|||
|
||||
@Test
|
||||
fun testLookupDefaultConfig() {
|
||||
assertEquals(url, Isgd.lookup(Config.Builder().shorturl(shortUrl).build()), "lookup(config)")
|
||||
assertEquals(url, Isgd.lookup(Config.Builder().shortUrl(shortUrl).build()), "lookup(config)")
|
||||
assertEquals(
|
||||
url, Isgd.lookup(
|
||||
Config.Builder().shorturl(shortVgdUrl).isVgd(true).build()
|
||||
Config.Builder().shortUrl(shortVgdUrl).isVgd(true).build()
|
||||
), "lookup(config:isVgd)"
|
||||
)
|
||||
}
|
||||
|
@ -119,12 +119,12 @@ class IsgdTest {
|
|||
fun testLookupJsonConfig() {
|
||||
assertEquals(
|
||||
"{ \"url\": \"$url\" }",
|
||||
Isgd.lookup(Config.Builder().shorturl(shortUrl).format(Format.JSON).build()), "lookup(config)"
|
||||
Isgd.lookup(Config.Builder().shortUrl(shortUrl).format(Format.JSON).build()), "lookup(config)"
|
||||
)
|
||||
|
||||
assertEquals(
|
||||
"test({ \"url\": \"$url\" });",
|
||||
Isgd.lookup(Config.Builder().shorturl(shortUrl).callback("test").format(Format.JSON).build()),
|
||||
Isgd.lookup(Config.Builder().shortUrl(shortUrl).callback("test").format(Format.JSON).build()),
|
||||
"lookup(config:callback)"
|
||||
)
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ class IsgdTest {
|
|||
fun testLookupXmlConfig() {
|
||||
assertEquals(
|
||||
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?><output><url>$url</url></output>",
|
||||
Isgd.lookup(Config.Builder().shorturl(shortUrl).format(Format.XML).build()),
|
||||
Isgd.lookup(Config.Builder().shortUrl(shortUrl).format(Format.XML).build()),
|
||||
"lookup(config:xml)"
|
||||
)
|
||||
}
|
||||
|
@ -172,7 +172,7 @@ class IsgdTest {
|
|||
assertFailsWith(
|
||||
message = "shorten(config:shorturl)",
|
||||
exceptionClass = IsgdException::class,
|
||||
block = { Isgd.shorten(Config.Builder(url).shorturl("test").build()) }
|
||||
block = { Isgd.shorten(Config.Builder(url).shortUrl("test").build()) }
|
||||
)
|
||||
}
|
||||
|
||||
|
@ -191,7 +191,7 @@ class IsgdTest {
|
|||
Isgd.shorten(Config.Builder().url(url).isVgd(true).build()),
|
||||
"shorten(config:isVgd)"
|
||||
)
|
||||
assertThat(Isgd.shorten(Config.Builder().url(url).logstats(true).build()), "shorten(config:callback)")
|
||||
assertThat(Isgd.shorten(Config.Builder().url(url).logStats(true).build()), "shorten(config:callback)")
|
||||
.matches("https://is.gd/\\w{6}".toRegex())
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue