Added ShortenConfig && LookupConfig

This commit is contained in:
Erik C. Thauvin 2024-06-03 17:59:57 -07:00
parent 63645f7cf4
commit e20934fc08
Signed by: erik
GPG key ID: 776702A6A2DA330E
15 changed files with 138 additions and 171 deletions

View file

@ -94,11 +94,10 @@ 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 Config.Builder()
.url("https://www.example.com/")
.shortUrl("foobar")
var config = new ShortenConfig.Builder("https://www.example.com/")
.shorturl("foobar")
.callback("test")
.logStats(true)
.logstats(true)
.format(Format.JSON)
.build();
@ -106,8 +105,8 @@ Isgd.shorten(config);
```
```java
var config = new Config.Builder()
.shortUrl("https://is.gd/Pt2sET")
var config = new LookupConfig.Builder("https://is.gd/Pt2sET")
.callback("test")
.format(Format.XML)
.build();

View file

@ -1,9 +1,9 @@
package com.example;
import net.thauvin.erik.isgd.Config;
import net.thauvin.erik.isgd.Format;
import net.thauvin.erik.isgd.Isgd;
import net.thauvin.erik.isgd.IsgdException;
import net.thauvin.erik.isgd.LookupConfig;
public final class IsgdSample {
public static void main(final String[] args) {
@ -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 LookupConfig.Builder(arg).format(Format.WEB).build()));
} else {
System.out.println(arg + " --> " + Isgd.shorten(arg));
}

View file

@ -5,7 +5,7 @@
<option name="linkedExternalProjectsSettings">
<GradleProjectSettings>
<option name="externalProjectPath" value="$PROJECT_DIR$" />
<option name="gradleJvm" value="#JAVA_HOME" />
<option name="gradleJvm" value="17" />
<option name="modules">
<set>
<option value="$PROJECT_DIR$" />

View file

@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="KotlinJpsPluginSettings">
<option name="version" value="1.9.20" />
<option name="version" value="2.0.0" />
</component>
</project>

View file

@ -2,11 +2,13 @@
<library name="Gradle: org.jetbrains:annotations:13.0" type="java-imported" external-system-id="GRADLE">
<properties groupId="org.jetbrains" artifactId="annotations" version="13.0" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar!/" />
</CLASSES>
<JAVADOC />
<JAVADOC>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/73368c3b0887f3adc2c2730dd1b95d7c3781aaf3/annotations-13.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0-sources.jar!/" />
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/5991ca87ef1fb5544943d9abc5a9a37583fabe03/annotations-13.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View file

@ -3,5 +3,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>

View file

@ -2,9 +2,9 @@
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/modules/isgd-examples.iml" filepath="$PROJECT_DIR$/.idea/modules/isgd-examples.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/isgd-examples.main.iml" filepath="$PROJECT_DIR$/.idea/modules/isgd-examples.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/isgd-examples.test.iml" filepath="$PROJECT_DIR$/.idea/modules/isgd-examples.test.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/isgd-shorten-examples-gradle.iml" filepath="$PROJECT_DIR$/.idea/modules/isgd-shorten-examples-gradle.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/isgd-shorten-examples-gradle.main.iml" filepath="$PROJECT_DIR$/.idea/modules/isgd-shorten-examples-gradle.main.iml" />
<module fileurl="file://$PROJECT_DIR$/.idea/modules/isgd-shorten-examples-gradle.test.iml" filepath="$PROJECT_DIR$/.idea/modules/isgd-shorten-examples-gradle.test.iml" />
</modules>
</component>
</project>

View file

@ -1,12 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="isgd-examples" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$/../..">
<excludeFolder url="file://$MODULE_DIR$/../../.gradle" />
<excludeFolder url="file://$MODULE_DIR$/../../build" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View file

@ -1,53 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="isgd-examples:main" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet external-system-id="GRADLE" type="kotlin-language" name="Kotlin">
<configuration version="5" platform="JVM 11" allPlatforms="JVM [11]" useProjectSettings="false">
<compilerSettings />
<compilerArguments>
<flagArguments>
<flagArg name="allowNoSourceFiles" arg="true" />
<flagArg name="noReflect" arg="true" />
<flagArg name="noStdlib" arg="true" />
</flagArguments>
<stringArguments>
<stringArg name="destination" arg="$MODULE_DIR$/../../build/classes/kotlin/main" />
<stringArg name="jvmTarget" arg="11" />
<stringArg name="moduleName" arg="isgd-examples" />
<stringArg name="apiVersion" arg="1.9" />
<stringArg name="languageVersion" arg="1.9" />
</stringArguments>
<arrayArguments>
<arrayArg name="pluginClasspaths">
<args>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-scripting-jvm/1.9.20/kotlin-scripting-jvm-1.9.20.jar</arg>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-scripting-common/1.9.20/kotlin-scripting-common-1.9.20.jar</arg>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.20/kotlin-stdlib-1.9.20.jar</arg>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar</arg>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-script-runtime/1.9.20/kotlin-script-runtime-1.9.20.jar</arg>
</args>
</arrayArg>
<arrayArg name="pluginOptions" />
</arrayArguments>
</compilerArguments>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<output url="file://$MODULE_DIR$/../../build/classes/java/main" />
<exclude-output />
<content url="file://$MODULE_DIR$/../../src/main">
<sourceFolder url="file://$MODULE_DIR$/../../src/main/java" isTestSource="false" />
<sourceFolder url="file://$MODULE_DIR$/../../src/main/kotlin" isTestSource="false" />
</content>
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Gradle: net.thauvin.erik:isgd-shorten:1.0.0" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.9.20" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: net.thauvin.erik.urlencoder:urlencoder-lib-jvm:1.4.0" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:1.9.10" level="project" />
</component>
</module>

View file

@ -1,53 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="isgd-examples:test" external.linked.project.path="$MODULE_DIR$/../.." external.root.project.path="$MODULE_DIR$/../.." external.system.id="GRADLE" external.system.module.group="" external.system.module.type="sourceSet" external.system.module.version="unspecified" type="JAVA_MODULE" version="4">
<component name="FacetManager">
<facet external-system-id="GRADLE" type="kotlin-language" name="Kotlin">
<configuration version="5" platform="JVM 11" allPlatforms="JVM [11]" useProjectSettings="false">
<additionalVisibleModuleNames>isgd-examples:main</additionalVisibleModuleNames>
<compilerSettings />
<compilerArguments>
<flagArguments>
<flagArg name="allowNoSourceFiles" arg="true" />
<flagArg name="noReflect" arg="true" />
<flagArg name="noStdlib" arg="true" />
</flagArguments>
<stringArguments>
<stringArg name="destination" arg="$MODULE_DIR$/../../build/classes/kotlin/test" />
<stringArg name="jvmTarget" arg="11" />
<stringArg name="moduleName" arg="isgd-examples_test" />
<stringArg name="apiVersion" arg="1.9" />
<stringArg name="languageVersion" arg="1.9" />
</stringArguments>
<arrayArguments>
<arrayArg name="pluginClasspaths">
<args>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-scripting-jvm/1.9.20/kotlin-scripting-jvm-1.9.20.jar</arg>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-scripting-common/1.9.20/kotlin-scripting-common-1.9.20.jar</arg>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.20/kotlin-stdlib-1.9.20.jar</arg>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar</arg>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-script-runtime/1.9.20/kotlin-script-runtime-1.9.20.jar</arg>
</args>
</arrayArg>
<arrayArg name="pluginOptions" />
</arrayArguments>
</compilerArguments>
</configuration>
</facet>
</component>
<component name="NewModuleRootManager">
<output-test url="file://$MODULE_DIR$/../../build/classes/java/test" />
<exclude-output />
<content url="file://$MODULE_DIR$/../../src/test" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="module" module-name="isgd-examples.main" />
<orderEntry type="library" name="Gradle: net.thauvin.erik:isgd-shorten:1.0.0" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.9.20" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains:annotations:13.0" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: net.thauvin.erik.urlencoder:urlencoder-lib-jvm:1.4.0" level="project" />
<orderEntry type="library" scope="RUNTIME" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:1.9.10" level="project" />
</component>
<component name="TestModuleProperties" production-module="isgd-examples.main" />
</module>

View file

@ -1,9 +1,9 @@
package com.example;
import net.thauvin.erik.isgd.Config;
import net.thauvin.erik.isgd.Format;
import net.thauvin.erik.isgd.Isgd;
import net.thauvin.erik.isgd.IsgdException;
import net.thauvin.erik.isgd.LookupConfig;
public final class IsgdSample {
public static void main(final String[] args) {
@ -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 LookupConfig.Builder(arg).format(Format.WEB).build()));
} else {
System.out.println(arg + " --> " + Isgd.shorten(arg));
}

View file

@ -75,7 +75,7 @@ class Isgd private constructor() {
*/
@JvmStatic
@Throws(IsgdException::class)
fun lookup(config: Config): String {
fun lookup(config: LookupConfig): String {
return lookup(
config.shorturl,
config.callback,
@ -89,9 +89,10 @@ class Isgd private constructor() {
*
* See the [is.gd API](https://is.gd/apilookupreference.php).
*
* @param The shorturl parameter is the shortened is.gd URL that you want to look up. You can either submit the
* full address (e.g. https://is.gd/example) or only the unique part (e.g. example). The address you submit
* should be properly formed; the API lookup function is not guaranteed to handle malformed URLs the same way as when you visit them manually.
* @param shorturl The shorturl parameter is the shortened is.gd URL that you want to look up. You can either
* submit the full address (e.g. `https://is.gd/example`) or only the unique part (e.g. `example`). The address
* you submit should be properly formed; the API lookup function is not guaranteed to handle malformed URLs the
* same way as when you visit them manually.
* @param callback The callback parameter is used to specify a callback function to wrap the returned data in
* when using JSON format. This can be useful when working with cross domain data. Even when using JSON format
* this parameter is optional.
@ -128,7 +129,7 @@ class Isgd private constructor() {
*/
@JvmStatic
@Throws(IsgdException::class)
fun shorten(config: Config): String {
fun shorten(config: ShortenConfig): String {
return shorten(
config.url,
config.shorturl,

View file

@ -0,0 +1,84 @@
/*
* LookupConfig.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.
*/
package net.thauvin.erik.isgd
/**
* Provides a builder to lookup an is.gd shortlink.
*/
class LookupConfig private constructor(builder: Builder) {
val shorturl: String = builder.shorturl
val callback: String = builder.callback
val format: Format = builder.format
val isVgd: Boolean = builder.isVgd
/**
* Configures the parameters to lookup an is.gd shortlink.
*
* See the [is.gd Lookup]() API.
*/
data class Builder(var shorturl: String) {
var callback: String = ""
var format: Format = Format.SIMPLE
var isVgd: Boolean = false
/**
* The shorturl parameter is the shortened is.gd URL that you want to look up. You can either submit the full
* address (e.g. `https://is.gd/example`) or only the unique part (e.g. `example`). The address you submit
* should be properly formed; the API lookup function is not guaranteed to handle malformed URLs the same way
* as when you visit them manually.
*/
fun shorturl(shorturl: String): Builder = apply { this.shorturl = shorturl }
/**
* The callback parameter is used to specify a callback function to wrap the returned data in
* when using JSON format. This can be useful when working with cross domain data. Even when using JSON format
* this parameter is optional.
*/
fun callback(callback: String): Builder = apply { this.callback = callback }
/**
* The format parameter determines what format is.gd uses to send output back to you (e.g. to
* tell you what your new shortened URL is or if an error has occurred).
*/
fun format(format: Format): Builder = apply { this.format = format }
/**
* Shorten using the `v.gd` domain.
*/
fun isVgd(isVgd: Boolean): Builder = apply { this.isVgd = isVgd }
/**
* Builds a new configuration.
*/
fun build() = LookupConfig(this)
}
}

View file

@ -1,5 +1,5 @@
/*
* Config.kt
* ShortenConfig.kt
*
* Copyright 2020-2024 Erik C. Thauvin (erik@thauvin.net)
*
@ -32,9 +32,9 @@
package net.thauvin.erik.isgd
/**
* Provides a builder to create/lookup an is.gd shortlink.
* Provides a builder to create an is.gd shortlink.
*/
class Config private constructor(builder: Builder) {
class ShortenConfig private constructor(builder: Builder) {
val url: String = builder.url
val shorturl: String = builder.shorturl
val callback: String = builder.callback
@ -43,16 +43,15 @@ class Config private constructor(builder: Builder) {
val isVgd: Boolean = builder.isVgd
/**
* Configures the parameters to create/lookup an is.gd shortlink.
* Configures the parameters to create an is.gd shortlink.
*
* See the [is.gd Shortening](https://is.gd/apishorteningreference.php) or
* [is.gd Lookup](https://is.gd/apilookupreference.php) APIs.
* See the [is.gd Shortening](https://is.gd/apishorteningreference.php) API.
*/
data class Builder(var url: String) {
var shorturl: String = "",
var callback: String = "",
var logstats: Boolean = false,
var format: Format = Format.SIMPLE,
var shorturl: String = ""
var callback: String = ""
var logstats: Boolean = false
var format: Format = Format.SIMPLE
var isVgd: Boolean = false
/**
@ -67,7 +66,7 @@ class Config private constructor(builder: Builder) {
* short URL might already be taken (this is very often the case with common words) so if you're using this
* option be prepared to respond to an error and get an alternative choice from your app's user.
*/
fun shortUrl(shortUrl: String): Builder = apply { this.shorturl = shortUrl }
fun shorturl(shorturl: String): Builder = apply { this.shorturl = shorturl }
/**
* The callback parameter is used to specify a callback function to wrap the returned data in
@ -85,7 +84,7 @@ class Config private constructor(builder: Builder) {
* parameter out of your API call if you don't require statistics on usage. See the
* [usage limits page](https://is.gd/usagelimits.php) for more information on this.
*/
fun logStats(logStats: Boolean): Builder = apply { this.logstats = logStats }
fun logstats(logstats: Boolean): Builder = apply { this.logstats = logstats }
/**
* The format parameter determines what format is.gd uses to send output back to you (e.g. to
@ -101,6 +100,6 @@ class Config private constructor(builder: Builder) {
/**
* Builds a new configuration.
*/
fun build() = Config(this)
fun build() = ShortenConfig(this)
}
}

View file

@ -66,7 +66,7 @@ class IsgdTest {
assertFailsWith(
message = "shorten(config:duplicate)",
exceptionClass = IsgdException::class,
block = { Isgd.shorten(Config.Builder().url(shortUrl).build()) }
block = { Isgd.shorten(ShortenConfig.Builder(shortUrl).build()) }
)
}
@ -84,7 +84,7 @@ class IsgdTest {
assertFailsWith(
message = "lookup(config:empty)",
exceptionClass = IllegalArgumentException::class,
block = { Isgd.lookup(Config.Builder().shortUrl("").build()) }
block = { Isgd.lookup(LookupConfig.Builder("").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(LookupConfig.Builder(shortUrl).build()), "lookup(config)")
assertEquals(
url, Isgd.lookup(
Config.Builder().shortUrl(shortVgdUrl).isVgd(true).build()
LookupConfig.Builder(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(LookupConfig.Builder(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(LookupConfig.Builder(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(LookupConfig.Builder(shortUrl).format(Format.XML).build()),
"lookup(config:xml)"
)
}
@ -166,13 +166,13 @@ class IsgdTest {
assertFailsWith(
message = "shorten(config:empty)",
exceptionClass = IllegalArgumentException::class,
block = { Isgd.shorten(Config.Builder().url("").build()) }
block = { Isgd.shorten(ShortenConfig.Builder("").build()) }
)
assertFailsWith(
message = "shorten(config:shorturl)",
exceptionClass = IsgdException::class,
block = { Isgd.shorten(Config.Builder(url).shortUrl("test").build()) }
block = { Isgd.shorten(ShortenConfig.Builder(url).shorturl("test").build()) }
)
}
@ -185,13 +185,13 @@ class IsgdTest {
@Test
fun testShortenDefaultConfig() {
assertEquals(shortUrl, Isgd.shorten(Config.Builder().url(url).build()), "shorten(config:url)")
assertEquals(shortUrl, Isgd.shorten(ShortenConfig.Builder(url).build()), "shorten(config:url)")
assertEquals(
shortVgdUrl,
Isgd.shorten(Config.Builder().url(url).isVgd(true).build()),
Isgd.shorten(ShortenConfig.Builder(url).isVgd(true).build()),
"shorten(config:isVgd)"
)
assertThat(Isgd.shorten(Config.Builder().url(url).logStats(true).build()), "shorten(config:callback)")
assertThat(Isgd.shorten(ShortenConfig.Builder(url).logstats(true).build()), "shorten(config:callback)")
.matches("https://is.gd/\\w{6}".toRegex())
}
@ -209,11 +209,11 @@ class IsgdTest {
fun testShortenJsonConfig() {
assertEquals(
"{ \"shorturl\": \"$shortUrl\" }",
Isgd.shorten(Config.Builder().url(url).format(Format.JSON).build()), "shorten(config:json)"
Isgd.shorten(ShortenConfig.Builder(url).format(Format.JSON).build()), "shorten(config:json)"
)
assertEquals(
"test({ \"shorturl\": \"$shortUrl\" });",
Isgd.shorten(Config.Builder().url(url).callback("test").format(Format.JSON).build()),
Isgd.shorten(ShortenConfig.Builder(url).callback("test").format(Format.JSON).build()),
"shorten(config:callback,json)"
)
}
@ -232,7 +232,7 @@ class IsgdTest {
assertEquals(
"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"yes\"?>" +
"<output><shorturl>$shortUrl</shorturl></output>",
Isgd.shorten(Config.Builder().url(url).format(Format.XML).build()),
Isgd.shorten(ShortenConfig.Builder(url).format(Format.XML).build()),
"shorten(config:xml)"
)
}
@ -244,7 +244,7 @@ class IsgdTest {
@Test
fun testShortenWebConfig() {
assertThat(Isgd.shorten(Config.Builder().url(url).format(Format.WEB).build()), "shorten(config:web)")
assertThat(Isgd.shorten(ShortenConfig.Builder(url).format(Format.WEB).build()), "shorten(config:web)")
.contains(shortUrl)
}
}