is.gd Shortener for Kotlin, Java & Android https://github.com/ethauvin/isgd-shorten
Find a file
2023-09-25 17:06:45 -07:00
.circleci Upgraded to Kotlin 1.7.20 2022-10-01 09:55:52 -07:00
.github/workflows Cleanup before 1.0 release 2023-09-25 17:06:45 -07:00
.idea Updated dependencies 2023-09-25 00:46:20 -07:00
config Minor cleanup 2023-09-25 03:19:39 -07:00
examples Cleanup before 1.0 release 2023-09-25 17:06:45 -07:00
gradle/wrapper Updated dependencies 2023-09-25 00:46:20 -07:00
src Made builder fields private 2023-09-25 10:55:32 -07:00
.editorconfig Initial commit. 2020-03-21 19:35:34 -07:00
.gitattributes Initial commit. 2020-03-21 19:35:34 -07:00
.github_changelog_generator Cleanup before 1.0 release 2023-09-25 17:06:45 -07:00
.gitignore Updated dependencies 2023-09-25 00:46:20 -07:00
.gitlab-ci.yml Updated dependencies 2023-09-25 00:46:20 -07:00
bitbucket-pipelines.yml Upgraded to Kotlin 1.7.20 2022-10-01 09:55:52 -07:00
build.gradle.kts Minor cleanup 2023-09-25 03:19:39 -07:00
CHANGELOG.md Cleanup before 1.0 release 2023-09-25 17:06:45 -07:00
gradle.properties Updated dependencies 2023-09-25 00:46:20 -07:00
gradlew Updated dependencies 2023-09-25 00:46:20 -07:00
gradlew.bat Updated dependencies 2023-09-25 00:46:20 -07:00
LICENSE.txt Updated copyright 2023-01-29 14:52:48 -08:00
pom.xml Cleanup before 1.0 release 2023-09-25 17:06:45 -07:00
README.md Cleanup before 1.0 release 2023-09-25 17:06:45 -07:00
settings.gradle.kts Cleanup before 1.0 release 2023-09-25 17:06:45 -07:00
version.properties Cleanup before 1.0 release 2023-09-25 17:06:45 -07:00

License (3-Clause BSD) Kotlin Nexus Snapshot release Maven Central

Quality Gate Status GitHub CI CircleCI

is.gd Shortener for Kotlin, Java & Android

A simple implementation of the is.gd URL shortening and lookup APIs.

Examples (TL;DR)

import net.thauvin.erik.isgd.Isgd

...

Isgd.shorten("https://www.example.com/") // returns https://is.gd/Pt2sET
Isgd.lookup("https://is.gd/Pt2sET") // returns https://www.example.com

JSON or XML

The is.gd API can return data in plain text (default), JSON or XML.

Isgd.shorten("https://www.example.com/", format = Format.JSON)

returns:

{ "shorturl": "https://is.gd/Pt2sET" }

Parameters

All of the is.gd API parameters are supported:

Isgd.shorten(
    url = url,
    shorturl="foobar",
    callback = "test",
    logstats = true,
    format = Format.JSON)

returns:

test({ "shorturl": "https://is.gd/foobar" });

Gradle

To use with Gradle, include the following dependency in your build file:

repositories {
    mavenCentral()
    maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } // only needed for SNAPSHOT
}

dependencies {
    implementation("net.thauvin.erik:isgd-shorten:1.0.0")
}

Instructions for using with Maven, Ivy, etc. can be found on Maven Central.

Java

To make it easier to use the library with Java, configuration builders are available:

var config = new Config.Builder()
        .url("https://www.example.com/")
        .shortUrl("foobar")
        .callback("test")
        .logStats(true)
        .format(Format.JSON)
        .build();

Isgd.shorten(config);
var config = new Config.Builder()
        .shortUrl("https://is.gd/Pt2sET")
        .format(Format.XML)
        .build();

Isgd.lookup(config);

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:

try {
    Isgd.shorten("https://is.gd/Pt2sET") // already shorten
} catch (e: IsgdException)
    println("Status Code: ${e.statusCode}")
    println("${e.message})
}
Status Code: 400
Error: Sorry, the URL you entered is on our internal blacklist. It may have been used abusively in the past, or it may link to another URL redirection service.

v.gd

Additionally, link can be shortened using v.gd by setting the isVgd flag:

Isgd.shorten("https://www.example.com/", isVgd = true) // returns https://v.gd/2z2ncj