Compare commits
No commits in common. "b7aee90edd5e1397449e6b4b074a344615c0a01a" and "85507a1e06dc2028051294ffbd85c941e863c121" have entirely different histories.
b7aee90edd
...
85507a1e06
11 changed files with 31 additions and 60 deletions
2
.github/workflows/gradle.yml
vendored
2
.github/workflows/gradle.yml
vendored
|
@ -39,7 +39,7 @@ jobs:
|
||||||
- name: Test with Gradle
|
- name: Test with Gradle
|
||||||
uses: gradle/gradle-build-action@v2
|
uses: gradle/gradle-build-action@v2
|
||||||
with:
|
with:
|
||||||
arguments: build check --stacktrace --scan
|
arguments: build check --stacktrace
|
||||||
|
|
||||||
- name: SonarCloud
|
- name: SonarCloud
|
||||||
if: success() && matrix.java-version == env.SONAR_JDK
|
if: success() && matrix.java-version == env.SONAR_JDK
|
||||||
|
|
|
@ -1 +0,0 @@
|
||||||
future-release=1.0.0
|
|
19
CHANGELOG.md
19
CHANGELOG.md
|
@ -1,19 +0,0 @@
|
||||||
# Changelog
|
|
||||||
|
|
||||||
## [1.0.0](https://github.com/ethauvin/isgd-shorten/tree/1.0.0) (2023-09-25)
|
|
||||||
|
|
||||||
[Full Changelog](https://github.com/ethauvin/isgd-shorten/compare/0.9.1...1.0.0)
|
|
||||||
|
|
||||||
**Implemented enhancements:**
|
|
||||||
|
|
||||||
- Add config builder [\#3](https://github.com/ethauvin/isgd-shorten/issues/3)
|
|
||||||
- Use UrlEncoder instead of java.net.URLEncoder [\#2](https://github.com/ethauvin/isgd-shorten/issues/2)
|
|
||||||
- Implement a way to retrieve the error response message. [\#1](https://github.com/ethauvin/isgd-shorten/issues/1)
|
|
||||||
|
|
||||||
## [0.9.1](https://github.com/ethauvin/isgd-shorten/tree/0.9.1) (2020-06-10)
|
|
||||||
|
|
||||||
[Full Changelog](https://github.com/ethauvin/isgd-shorten/compare/60c449feed0ddced600d7135766243e7058d683a...0.9.1)
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
\* *This Changelog was automatically generated by [github_changelog_generator](https://github.com/github-changelog-generator/github-changelog-generator)*
|
|
14
README.md
14
README.md
|
@ -24,7 +24,8 @@ Isgd.lookup("https://is.gd/Pt2sET") // returns https://www.example.com
|
||||||
|
|
||||||
```
|
```
|
||||||
|
|
||||||
- View [Kotlin](https://github.com/ethauvin/isgd-shorten/blob/master/examples/src/main/kotlin/com/example/IsgdExample.kt) or [Java](https://github.com/ethauvin/isgd-shorten/blob/master/examples/src/main/java/com/example/IsgdSample.java) Examples.
|
- View [Kotlin](https://github.com/ethauvin/isgd-shorten/blob/master/examples/src/main/kotlin/com/example/IsgdExample.kt) or [Java](https://github.com/ethauvin/isgd-shorten/blob/master/examples/src/main/java/com/example/IsgdSample.java) Examples.
|
||||||
|
|
||||||
|
|
||||||
### JSON or XML
|
### JSON or XML
|
||||||
|
|
||||||
|
@ -52,13 +53,11 @@ Isgd.shorten(
|
||||||
logstats = true,
|
logstats = true,
|
||||||
format = Format.JSON)
|
format = Format.JSON)
|
||||||
```
|
```
|
||||||
|
|
||||||
returns:
|
returns:
|
||||||
|
|
||||||
```js
|
```js
|
||||||
test({ "shorturl": "https://is.gd/foobar" });
|
test({ "shorturl": "https://is.gd/foobar" });
|
||||||
```
|
```
|
||||||
|
|
||||||
### Gradle
|
### Gradle
|
||||||
|
|
||||||
To use with [Gradle](https://gradle.org/), include the following dependency in your [build](https://github.com/ethauvin/isgd-shorten/blob/master/examples/build.gradle.kts) file:
|
To use with [Gradle](https://gradle.org/), include the following dependency in your [build](https://github.com/ethauvin/isgd-shorten/blob/master/examples/build.gradle.kts) file:
|
||||||
|
@ -70,10 +69,9 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("net.thauvin.erik:isgd-shorten:1.0.0")
|
implementation("net.thauvin.erik:isgd-shorten:0.9.2")
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
Instructions for using with Maven, Ivy, etc. can be found on [Maven Central](https://central.sonatype.com/artifact/net.thauvin.erik/isgd-shorten).
|
Instructions for using with Maven, Ivy, etc. can be found on [Maven Central](https://central.sonatype.com/artifact/net.thauvin.erik/isgd-shorten).
|
||||||
|
|
||||||
## Java
|
## Java
|
||||||
|
@ -83,15 +81,14 @@ To make it easier to use the library with Java, configuration builders are avail
|
||||||
```java
|
```java
|
||||||
var config = new Config.Builder()
|
var config = new Config.Builder()
|
||||||
.url("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();
|
||||||
|
|
||||||
Isgd.shorten(config);
|
Isgd.shorten(config);
|
||||||
```
|
```
|
||||||
|
|
||||||
```java
|
```java
|
||||||
var config = new Config.Builder()
|
var config = new Config.Builder()
|
||||||
.shortUrl("https://is.gd/Pt2sET")
|
.shortUrl("https://is.gd/Pt2sET")
|
||||||
|
@ -100,7 +97,6 @@ var config = new Config.Builder()
|
||||||
|
|
||||||
Isgd.lookup(config);
|
Isgd.lookup(config);
|
||||||
```
|
```
|
||||||
|
|
||||||
### Errors
|
### Errors
|
||||||
|
|
||||||
An `IsgdException` is thrown when an API error occurs. The error message (text, XML or JSON) and HTTP status code can be retrieved as follows:
|
An `IsgdException` is thrown when an API error occurs. The error message (text, XML or JSON) and HTTP status code can be retrieved as follows:
|
||||||
|
|
|
@ -16,7 +16,7 @@ repositories {
|
||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
implementation("net.thauvin.erik:isgd-shorten:1.0.0")
|
implementation("net.thauvin.erik:isgd-shorten:0.9.2-SNAPSHOT")
|
||||||
}
|
}
|
||||||
|
|
||||||
java {
|
java {
|
||||||
|
|
|
@ -1,7 +1,5 @@
|
||||||
package com.example;
|
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.Isgd;
|
||||||
import net.thauvin.erik.isgd.IsgdException;
|
import net.thauvin.erik.isgd.IsgdException;
|
||||||
|
|
||||||
|
@ -12,7 +10,6 @@ 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()));
|
|
||||||
} else {
|
} else {
|
||||||
System.out.println(arg + " --> " + Isgd.shorten(arg));
|
System.out.println(arg + " --> " + Isgd.shorten(arg));
|
||||||
}
|
}
|
||||||
|
|
2
pom.xml
2
pom.xml
|
@ -8,7 +8,7 @@
|
||||||
<modelVersion>4.0.0</modelVersion>
|
<modelVersion>4.0.0</modelVersion>
|
||||||
<groupId>net.thauvin.erik</groupId>
|
<groupId>net.thauvin.erik</groupId>
|
||||||
<artifactId>isgd-shorten</artifactId>
|
<artifactId>isgd-shorten</artifactId>
|
||||||
<version>1.0.0</version>
|
<version>0.9.2-SNAPSHOT</version>
|
||||||
<name>isgd-shorten</name>
|
<name>isgd-shorten</name>
|
||||||
<description>A simple implementation of the is.gd URL shortening and lookup APIs</description>
|
<description>A simple implementation of the is.gd URL shortening and lookup APIs</description>
|
||||||
<url>https://github.com/ethauvin/isgd-shorten</url>
|
<url>https://github.com/ethauvin/isgd-shorten</url>
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
plugins {
|
plugins {
|
||||||
id("com.gradle.enterprise").version("3.15")
|
id("com.gradle.enterprise").version("3.6.3")
|
||||||
}
|
}
|
||||||
|
|
||||||
gradleEnterprise {
|
gradleEnterprise {
|
||||||
|
|
|
@ -44,21 +44,19 @@ class Config private constructor(
|
||||||
) {
|
) {
|
||||||
/**
|
/**
|
||||||
* Configures the parameters to create/lookup an is.gd shortlink.
|
* Configures the parameters to create/lookup an is.gd shortlink.
|
||||||
*
|
|
||||||
* See the [is.gd API](https://is.gd/apishorteningreference.php).
|
|
||||||
*/
|
*/
|
||||||
data class Builder(
|
data class Builder(
|
||||||
private var url: String = "",
|
var url: String = "",
|
||||||
private var shorturl: String = "",
|
var shorturl: String = "",
|
||||||
private var callback: String = "",
|
var callback: String = "",
|
||||||
private var logstats: Boolean = false,
|
var logstats: Boolean = false,
|
||||||
private var format: Format = Format.SIMPLE,
|
var format: Format = Format.SIMPLE,
|
||||||
private var isVgd: Boolean = false
|
var isVgd: Boolean = false
|
||||||
) {
|
) {
|
||||||
fun url(url: String) = apply { this.url = url }
|
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 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 format(format: Format) = apply { this.format = format }
|
||||||
fun isVgd(isVgd: Boolean) = apply { this.isVgd = isVgd }
|
fun isVgd(isVgd: Boolean) = apply { this.isVgd = isVgd }
|
||||||
|
|
||||||
|
|
|
@ -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(Config.Builder().shorturl("").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(Config.Builder().shorturl(shortUrl).build()), "lookup(config)")
|
||||||
assertEquals(
|
assertEquals(
|
||||||
url, Isgd.lookup(
|
url, Isgd.lookup(
|
||||||
Config.Builder().shortUrl(shortVgdUrl).isVgd(true).build()
|
Config.Builder().shorturl(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(Config.Builder().shorturl(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(Config.Builder().shorturl(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(Config.Builder().shorturl(shortUrl).format(Format.XML).build()),
|
||||||
"lookup(config:xml)"
|
"lookup(config:xml)"
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ class IsgdTest {
|
||||||
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(Config.Builder(url).shorturl("test").build()) }
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -191,7 +191,7 @@ class IsgdTest {
|
||||||
Isgd.shorten(Config.Builder().url(url).isVgd(true).build()),
|
Isgd.shorten(Config.Builder().url(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(Config.Builder().url(url).logstats(true).build()), "shorten(config:callback)")
|
||||||
.matches("https://is.gd/\\w{6}".toRegex())
|
.matches("https://is.gd/\\w{6}".toRegex())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
#Generated by the Semver Plugin for Gradle
|
#Generated by the Semver Plugin for Gradle
|
||||||
#Sun May 02 21:57:08 PDT 2021
|
#Sun May 02 21:57:08 PDT 2021
|
||||||
version.buildmeta=
|
version.buildmeta=
|
||||||
version.major=1
|
version.major=0
|
||||||
version.minor=0
|
version.minor=9
|
||||||
version.patch=0
|
version.patch=2
|
||||||
version.prerelease=
|
version.prerelease=SNAPSHOT
|
||||||
version.semver=1.0.0
|
version.semver=0.9.2-SNAPSHOT
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue