Compare commits

...

2 commits

Author SHA1 Message Date
e20934fc08
Added ShortenConfig && LookupConfig 2024-06-03 17:59:57 -07:00
63645f7cf4
Bumped Gradle to version 8.8 2024-06-03 17:58:31 -07:00
26 changed files with 231 additions and 187 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: To make it easier to use the library with Java, configuration builders are available:
```java ```java
var config = new Config.Builder() var config = new ShortenConfig.Builder("https://www.example.com/")
.url("https://www.example.com/") .shorturl("foobar")
.shortUrl("foobar")
.callback("test") .callback("test")
.logStats(true) .logstats(true)
.format(Format.JSON) .format(Format.JSON)
.build(); .build();
@ -106,8 +105,8 @@ Isgd.shorten(config);
``` ```
```java ```java
var config = new Config.Builder() var config = new LookupConfig.Builder("https://is.gd/Pt2sET")
.shortUrl("https://is.gd/Pt2sET") .callback("test")
.format(Format.XML) .format(Format.XML)
.build(); .build();

View file

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

View file

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

View file

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

View file

@ -1,8 +1,8 @@
<component name="libraryTable"> <component name="libraryTable">
<library name="Gradle: net.thauvin.erik:isgd-shorten:1.0.0" type="java-imported" external-system-id="GRADLE"> <library name="Gradle: net.thauvin.erik:isgd-shorten:1.0.2-SNAPSHOT" type="java-imported" external-system-id="GRADLE">
<properties groupId="net.thauvin.erik" artifactId="isgd-shorten" version="1.0.0" /> <properties groupId="net.thauvin.erik" artifactId="isgd-shorten" version="1.0.2-SNAPSHOT" />
<CLASSES> <CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/net/thauvin/erik/isgd-shorten/1.0.0/isgd-shorten-1.0.0.jar!/" /> <root url="jar://$MAVEN_REPOSITORY$/net/thauvin/erik/isgd-shorten/1.0.2-SNAPSHOT/isgd-shorten-1.0.2-SNAPSHOT.jar!/" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES /> <SOURCES />

View file

@ -1,12 +0,0 @@
<component name="libraryTable">
<library name="Gradle: net.thauvin.erik.urlencoder:urlencoder-lib-jvm:1.4.0" type="java-imported" external-system-id="GRADLE">
<properties groupId="net.thauvin.erik.urlencoder" artifactId="urlencoder-lib-jvm" version="1.4.0" />
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.thauvin.erik.urlencoder/urlencoder-lib-jvm/1.4.0/5ddab42b66d8a17e40c17655b9d54f7474296c7/urlencoder-lib-jvm-1.4.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.thauvin.erik.urlencoder/urlencoder-lib-jvm/1.4.0/f14b98a2fc30f00c3fb1cdf65bcb470926fd0e78/urlencoder-lib-jvm-1.4.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View file

@ -0,0 +1,10 @@
<component name="libraryTable">
<library name="Gradle: net.thauvin.erik.urlencoder:urlencoder-lib-jvm:1.5.0" type="java-imported" external-system-id="GRADLE">
<properties groupId="net.thauvin.erik.urlencoder" artifactId="urlencoder-lib-jvm" version="1.5.0" />
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/net.thauvin.erik.urlencoder/urlencoder-lib-jvm/1.5.0/93179364d9e915b17baa4160877fa770154e9aa5/urlencoder-lib-jvm-1.5.0.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View file

@ -2,11 +2,13 @@
<library name="Gradle: org.jetbrains:annotations:13.0" type="java-imported" external-system-id="GRADLE"> <library name="Gradle: org.jetbrains:annotations:13.0" type="java-imported" external-system-id="GRADLE">
<properties groupId="org.jetbrains" artifactId="annotations" version="13.0" /> <properties groupId="org.jetbrains" artifactId="annotations" version="13.0" />
<CLASSES> <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> </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> <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> </SOURCES>
</library> </library>
</component> </component>

View file

@ -1,12 +0,0 @@
<component name="libraryTable">
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:1.9.20" type="java-imported" external-system-id="GRADLE">
<properties groupId="org.jetbrains.kotlin" artifactId="kotlin-stdlib" version="1.9.20" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.20/kotlin-stdlib-1.9.20.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.20/kotlin-stdlib-1.9.20-sources.jar!/" />
</SOURCES>
</library>
</component>

View file

@ -0,0 +1,14 @@
<component name="libraryTable">
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:2.0.0" type="java-imported" external-system-id="GRADLE">
<properties groupId="org.jetbrains.kotlin" artifactId="kotlin-stdlib" version="2.0.0" />
<CLASSES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.0.0/b48df2c4aede9586cc931ead433bc02d6fd7879e/kotlin-stdlib-2.0.0.jar!/" />
</CLASSES>
<JAVADOC>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.0.0/2ad14aed781c4a73ed4dbb421966d408a0a06686/kotlin-stdlib-2.0.0-javadoc.jar!/" />
</JAVADOC>
<SOURCES>
<root url="jar://$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.0.0/84cdfeb1d3e1b3f72cc4e0a3803c85c4727312f1/kotlin-stdlib-2.0.0-sources.jar!/" />
</SOURCES>
</library>
</component>

View file

@ -1,12 +0,0 @@
<component name="libraryTable">
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-common:1.9.10" type="kotlin.common" external-system-id="GRADLE">
<properties groupId="org.jetbrains.kotlin" artifactId="kotlin-stdlib-common" version="1.9.10" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.9.10/kotlin-stdlib-common-1.9.10.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-common/1.9.10/kotlin-stdlib-common-1.9.10-sources.jar!/" />
</SOURCES>
</library>
</component>

View file

@ -1,10 +0,0 @@
<component name="libraryTable">
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk7:1.9.10" type="java-imported" external-system-id="GRADLE">
<properties groupId="org.jetbrains.kotlin" artifactId="kotlin-stdlib-jdk7" version="1.9.10" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk7/1.9.10/kotlin-stdlib-jdk7-1.9.10.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View file

@ -1,10 +0,0 @@
<component name="libraryTable">
<library name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10" type="java-imported" external-system-id="GRADLE">
<properties groupId="org.jetbrains.kotlin" artifactId="kotlin-stdlib-jdk8" version="1.9.10" />
<CLASSES>
<root url="jar://$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib-jdk8/1.9.10/kotlin-stdlib-jdk8-1.9.10.jar!/" />
</CLASSES>
<JAVADOC />
<SOURCES />
</library>
</component>

View file

@ -3,5 +3,5 @@
<component name="PDMPlugin"> <component name="PDMPlugin">
<option name="skipTestSources" value="false" /> <option name="skipTestSources" value="false" />
</component> </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> </project>

View file

@ -2,9 +2,9 @@
<project version="4"> <project version="4">
<component name="ProjectModuleManager"> <component name="ProjectModuleManager">
<modules> <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-shorten-examples-gradle.iml" filepath="$PROJECT_DIR$/.idea/modules/isgd-shorten-examples-gradle.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-shorten-examples-gradle.main.iml" filepath="$PROJECT_DIR$/.idea/modules/isgd-shorten-examples-gradle.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.test.iml" filepath="$PROJECT_DIR$/.idea/modules/isgd-shorten-examples-gradle.test.iml" />
</modules> </modules>
</component> </component>
</project> </project>

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,5 +1,5 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <module external.linked.project.id="isgd-shorten-examples-gradle" 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"> <component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output /> <exclude-output />
<content url="file://$MODULE_DIR$/../.."> <content url="file://$MODULE_DIR$/../..">

View file

@ -1,9 +1,8 @@
<?xml version="1.0" encoding="UTF-8"?> <?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"> <module external.linked.project.id="isgd-shorten-examples-gradle: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"> <component name="FacetManager">
<facet external-system-id="GRADLE" type="kotlin-language" name="Kotlin"> <facet external-system-id="GRADLE" type="kotlin-language" name="Kotlin">
<configuration version="5" platform="JVM 11" allPlatforms="JVM [11]" useProjectSettings="false"> <configuration version="5" platform="JVM 11" allPlatforms="JVM [11]" useProjectSettings="false">
<compilerSettings />
<compilerArguments> <compilerArguments>
<flagArguments> <flagArguments>
<flagArg name="allowNoSourceFiles" arg="true" /> <flagArg name="allowNoSourceFiles" arg="true" />
@ -13,18 +12,18 @@
<stringArguments> <stringArguments>
<stringArg name="destination" arg="$MODULE_DIR$/../../build/classes/kotlin/main" /> <stringArg name="destination" arg="$MODULE_DIR$/../../build/classes/kotlin/main" />
<stringArg name="jvmTarget" arg="11" /> <stringArg name="jvmTarget" arg="11" />
<stringArg name="moduleName" arg="isgd-examples" /> <stringArg name="moduleName" arg="isgd-shorten-examples-gradle" />
<stringArg name="apiVersion" arg="1.9" /> <stringArg name="apiVersion" arg="2.0" />
<stringArg name="languageVersion" arg="1.9" /> <stringArg name="languageVersion" arg="2.0" />
</stringArguments> </stringArguments>
<arrayArguments> <arrayArguments>
<arrayArg name="pluginClasspaths"> <arrayArg name="pluginClasspaths">
<args> <args>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-scripting-jvm/1.9.20/kotlin-scripting-jvm-1.9.20.jar</arg> <arg>$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-scripting-jvm/2.0.0/11209b97b2495fb3755f2e2e4fb64abb7cd9b4c0/kotlin-scripting-jvm-2.0.0.jar</arg>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-scripting-common/1.9.20/kotlin-scripting-common-1.9.20.jar</arg> <arg>$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-scripting-common/2.0.0/f90871227cdcd06fd4fecb086fa03e7fa375bae3/kotlin-scripting-common-2.0.0.jar</arg>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/kotlin/kotlin-stdlib/1.9.20/kotlin-stdlib-1.9.20.jar</arg> <arg>$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.0.0/b48df2c4aede9586cc931ead433bc02d6fd7879e/kotlin-stdlib-2.0.0.jar</arg>
<arg>$MAVEN_REPOSITORY$/org/jetbrains/annotations/13.0/annotations-13.0.jar</arg> <arg>$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/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> <arg>$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-script-runtime/2.0.0/fdc27dd047d592fa41d2dfa21e7621287a361612/kotlin-script-runtime-2.0.0.jar</arg>
</args> </args>
</arrayArg> </arrayArg>
<arrayArg name="pluginOptions" /> <arrayArg name="pluginOptions" />
@ -42,12 +41,9 @@
</content> </content>
<orderEntry type="inheritedJdk" /> <orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" /> <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: net.thauvin.erik:isgd-shorten:1.0.2-SNAPSHOT" 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:2.0.0" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib-jdk8:1.9.10" level="project" /> <orderEntry type="library" name="Gradle: net.thauvin.erik.urlencoder:urlencoder-lib-jvm:1.5.0" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains:annotations:13.0" 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>
</module> </module>

View file

@ -0,0 +1,49 @@
<?xml version="1.0" encoding="UTF-8"?>
<module external.linked.project.id="isgd-shorten-examples-gradle: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-shorten-examples-gradle:main</additionalVisibleModuleNames>
<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-shorten-examples-gradle_test" />
<stringArg name="apiVersion" arg="2.0" />
<stringArg name="languageVersion" arg="2.0" />
</stringArguments>
<arrayArguments>
<arrayArg name="pluginClasspaths">
<args>
<arg>$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-scripting-jvm/2.0.0/11209b97b2495fb3755f2e2e4fb64abb7cd9b4c0/kotlin-scripting-jvm-2.0.0.jar</arg>
<arg>$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-scripting-common/2.0.0/f90871227cdcd06fd4fecb086fa03e7fa375bae3/kotlin-scripting-common-2.0.0.jar</arg>
<arg>$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-stdlib/2.0.0/b48df2c4aede9586cc931ead433bc02d6fd7879e/kotlin-stdlib-2.0.0.jar</arg>
<arg>$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains/annotations/13.0/919f0dfe192fb4e063e7dacadee7f8bb9a2672a9/annotations-13.0.jar</arg>
<arg>$USER_HOME$/.gradle/caches/modules-2/files-2.1/org.jetbrains.kotlin/kotlin-script-runtime/2.0.0/fdc27dd047d592fa41d2dfa21e7621287a361612/kotlin-script-runtime-2.0.0.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-shorten-examples-gradle.main" />
<orderEntry type="library" name="Gradle: net.thauvin.erik:isgd-shorten:1.0.2-SNAPSHOT" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains.kotlin:kotlin-stdlib:2.0.0" level="project" />
<orderEntry type="library" name="Gradle: net.thauvin.erik.urlencoder:urlencoder-lib-jvm:1.5.0" level="project" />
<orderEntry type="library" name="Gradle: org.jetbrains:annotations:13.0" level="project" />
</component>
<component name="TestModuleProperties" production-module="isgd-shorten-examples-gradle.main" />
</module>

View file

@ -1,6 +1,6 @@
distributionBase=GRADLE_USER_HOME distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-8.7-bin.zip distributionUrl=https\://services.gradle.org/distributions/gradle-8.8-bin.zip
networkTimeout=10000 networkTimeout=10000
validateDistributionUrl=true validateDistributionUrl=true
zipStoreBase=GRADLE_USER_HOME zipStoreBase=GRADLE_USER_HOME

View file

@ -55,7 +55,7 @@
# Darwin, MinGW, and NonStop. # Darwin, MinGW, and NonStop.
# #
# (3) This script is generated from the Groovy template # (3) This script is generated from the Groovy template
# https://github.com/gradle/gradle/blob/HEAD/subprojects/plugins/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt # https://github.com/gradle/gradle/blob/HEAD/platforms/jvm/plugins-application/src/main/resources/org/gradle/api/internal/plugins/unixStartScript.txt
# within the Gradle project. # within the Gradle project.
# #
# You can find Gradle at https://github.com/gradle/gradle/. # You can find Gradle at https://github.com/gradle/gradle/.

View file

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

View file

@ -75,7 +75,7 @@ class Isgd private constructor() {
*/ */
@JvmStatic @JvmStatic
@Throws(IsgdException::class) @Throws(IsgdException::class)
fun lookup(config: Config): String { fun lookup(config: LookupConfig): String {
return lookup( return lookup(
config.shorturl, config.shorturl,
config.callback, config.callback,
@ -89,9 +89,10 @@ class Isgd private constructor() {
* *
* See the [is.gd API](https://is.gd/apilookupreference.php). * 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 * @param shorturl The shorturl parameter is the shortened is.gd URL that you want to look up. You can either
* full address (e.g. https://is.gd/example) or only the unique part (e.g. example). The address you submit * submit the full address (e.g. `https://is.gd/example`) or only the unique part (e.g. `example`). The address
* should be properly formed; the API lookup function is not guaranteed to handle malformed URLs the same way as when you visit them manually. * 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 * @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 * when using JSON format. This can be useful when working with cross domain data. Even when using JSON format
* this parameter is optional. * this parameter is optional.
@ -128,7 +129,7 @@ class Isgd private constructor() {
*/ */
@JvmStatic @JvmStatic
@Throws(IsgdException::class) @Throws(IsgdException::class)
fun shorten(config: Config): String { fun shorten(config: ShortenConfig): String {
return shorten( return shorten(
config.url, config.url,
config.shorturl, 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) * Copyright 2020-2024 Erik C. Thauvin (erik@thauvin.net)
* *
@ -32,9 +32,9 @@
package net.thauvin.erik.isgd 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 url: String = builder.url
val shorturl: String = builder.shorturl val shorturl: String = builder.shorturl
val callback: String = builder.callback val callback: String = builder.callback
@ -43,19 +43,17 @@ class Config private constructor(builder: Builder) {
val isVgd: Boolean = builder.isVgd 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 * See the [is.gd Shortening](https://is.gd/apishorteningreference.php) API.
* [is.gd Lookup](https://is.gd/apilookupreference.php) APIs.
*/ */
data class Builder( data class Builder(var url: String) {
var url: String = "", var shorturl: String = ""
var shorturl: String = "", var callback: String = ""
var callback: String = "", var logstats: Boolean = false
var logstats: Boolean = false, var format: Format = Format.SIMPLE
var format: Format = Format.SIMPLE,
var isVgd: Boolean = false var isVgd: Boolean = false
) {
/** /**
* The url parameter is the address that you want to shorten. * The url parameter is the address that you want to shorten.
*/ */
@ -68,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 * 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. * 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 * The callback parameter is used to specify a callback function to wrap the returned data in
@ -86,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 * 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. * [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 * The format parameter determines what format is.gd uses to send output back to you (e.g. to
@ -102,6 +100,6 @@ class Config private constructor(builder: Builder) {
/** /**
* Builds a new configuration. * Builds a new configuration.
*/ */
fun build() = Config(this) fun build() = ShortenConfig(this)
} }
} }

View file

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