96 lines
3.7 KiB
Markdown
96 lines
3.7 KiB
Markdown
[](https://opensource.org/licenses/BSD-3-Clause)
|
|
[](https://kotlinlang.org/)
|
|
[](https://oss.sonatype.org/content/repositories/snapshots/net/thauvin/erik/isgd-shorten/)
|
|
[](https://github.com/ethauvin/isgd-shorten/releases/latest)
|
|
[](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/isgd-shorten)
|
|
|
|
[](https://sonarcloud.io/dashboard?id=ethauvin_isgd-shorten)
|
|
[](https://github.com/ethauvin/isgd-shorten/actions/workflows/gradle.yml)
|
|
[](https://circleci.com/gh/ethauvin/isgd-shorten/tree/master)
|
|
|
|
# [is.gd](https://is.gd/developers.php) Shortener for Kotlin, Java & Android
|
|
|
|
A simple implementation of the [is.gd](https://is.gd/) URL shortening and lookup [APIs](https://is.gd/developers.php).
|
|
|
|
## Examples (TL;DR)
|
|
|
|
```kotlin
|
|
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
|
|
|
|
```
|
|
|
|
- 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
|
|
|
|
The [is.gd API](https://is.gd/developers.php) can return data in plain text (default), JSON or XML.
|
|
|
|
```kotlin
|
|
Isgd.shorten("https://www.example.com/", format = Format.JSON)
|
|
```
|
|
|
|
returns:
|
|
|
|
```json
|
|
{ "shorturl": "https://is.gd/Pt2sET" }
|
|
```
|
|
|
|
### Parameters
|
|
|
|
All of the [is.gd API](https://is.gd/developers.php) parameters are supported:
|
|
|
|
```kotlin
|
|
Isgd.shorten(url = url, shorturl="foobar", callback = "test", logstats = true, format = Format.JSON)
|
|
```
|
|
returns:
|
|
|
|
```js
|
|
test({ "shorturl": "https://is.gd/foobar" });
|
|
```
|
|
### 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:
|
|
|
|
```gradle
|
|
repositories {
|
|
mavenCentral()
|
|
maven { url = uri("https://oss.sonatype.org/content/repositories/snapshots") } // only needed for SNAPSHOT
|
|
}
|
|
|
|
dependencies {
|
|
implementation("net.thauvin.erik:isgd-shorten:0.9.2")
|
|
}
|
|
```
|
|
Instructions for using with Maven, Ivy, etc. can be found on [Maven Central](https://maven-badges.herokuapp.com/maven-central/net.thauvin.erik/isgd-shorten).
|
|
|
|
### 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:
|
|
|
|
```kotlin
|
|
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](https://v.gd/) by setting the `isVgd` flag:
|
|
|
|
```kotlin
|
|
Isgd.shorten("https://www.example.com/", isVgd = true) // returns https://v.gd/2z2ncj
|
|
```
|