bitly-shorten

Bitly Shortener for Kotlin/Java

License

License

Categories

Categories

Net
GroupId

GroupId

net.thauvin.erik
ArtifactId

ArtifactId

bitly-shorten
Last Version

Last Version

0.9.3
Release Date

Release Date

Type

Type

jar
Description

Description

bitly-shorten
Bitly Shortener for Kotlin/Java
Project URL

Project URL

https://github.com/ethauvin/bitly-shorten
Source Code Management

Source Code Management

https://github.com/ethauvin/bitly-shorten

Download bitly-shorten

How to add to project

<!-- https://jarcasting.com/artifacts/net.thauvin.erik/bitly-shorten/ -->
<dependency>
    <groupId>net.thauvin.erik</groupId>
    <artifactId>bitly-shorten</artifactId>
    <version>0.9.3</version>
</dependency>
// https://jarcasting.com/artifacts/net.thauvin.erik/bitly-shorten/
implementation 'net.thauvin.erik:bitly-shorten:0.9.3'
// https://jarcasting.com/artifacts/net.thauvin.erik/bitly-shorten/
implementation ("net.thauvin.erik:bitly-shorten:0.9.3")
'net.thauvin.erik:bitly-shorten:jar:0.9.3'
<dependency org="net.thauvin.erik" name="bitly-shorten" rev="0.9.3">
  <artifact name="bitly-shorten" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.thauvin.erik', module='bitly-shorten', version='0.9.3')
)
libraryDependencies += "net.thauvin.erik" % "bitly-shorten" % "0.9.3"
[net.thauvin.erik/bitly-shorten "0.9.3"]

Dependencies

compile (1)

Group / Artifact Type Version
org.jetbrains.kotlin : kotlin-stdlib-jdk8 jar 1.4.31

runtime (3)

Group / Artifact Type Version
com.squareup.okhttp3 : okhttp jar 4.9.1
com.squareup.okhttp3 : logging-interceptor jar 4.9.1
org.json : json jar 20210307

Project Modules

There are no modules declared in this project.

License (3-Clause BSD) Release Maven Central

Known Vulnerabilities Quality Gate Status Build Status CircleCI

Bitly Shortener for Kotlin/Java/Android

A simple implementation of the link shortening (Bitlinks) abilities of the Bitly v4 API.

Examples (TL;DR)

val bitly = Bitly(/* "YOUR_API_ACCESS_TOKEN from https://bitly.is/accesstoken" */)

// Shorten
bitly.bitlinks().shorten("https://erik.thauvin.net/blog")

// Expand
bitly.bitlinks().expand("https://bit.ly/380ojFd")

// Clicks Summary
bitly.bitlinks().clicks("https://bit.ly/380ojFd")

// Create a bitlink
bitly.bitlinks().create(title = "Erik's Weblog", long_url = "https://erik.thauvin.net/blog/")

// Update a bitlink
bitly.bitlinks().update("https://bit.ly/380ojFd", title="Erik's Weblog", tags = arrayOf("blog", "weblog"))

API Access Token

The Bitly API Access Token can be specified directly as well as via the BITLY_ACCESS_TOKEN environment variable or properties key.

// Env Variable or System Property
val bitly = Bitly()

// Properties file path
val bitly = Bitly(File("my.properties"))
# my.properties
BITLY_ACCESS_TOKEN=abc123def456ghi789jkl0

Gradle, Maven, etc.

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

dependencies {
    implementation("net.thauvin.erik:bitly-shorten:0.9.3")
}

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

JSON

All implemented API calls can return the full JSON responses:

bitly.bitlinks().shorten("https://www.erik.thauvin.net/blog", toJson = true)
{
    "created_at": "2020-02-26T06:50:08+0000",
    "link": "https://bit.ly/380ojFd",
    "id": "bit.ly/380ojFd",
    "long_url": "https://erik.thauvin.net/blog"
}

You can also access the last response from implemented API calls using:

val bitlinks = Bitlinks(apikey)

val shortUrl = bitlinks.shorten(longUrl)

val response = bitlinks.lastCallResponse

if (response.isSuccessful) {
    println(response.body)
}

Non-implemented API calls can also be called directly:

val response = bitly.call("/user".toEndPoint(), method = Methods.GET)
if (response.isSuccessful) {
    println(response.body)
}
{
    "created": "2009-06-12T19:00:45+0000",
    "modified": "2016-11-11T19:50:33+0000",
    "login": "johndoe",
    "is_active": true,
    "is_2fa_enabled": true,
    "name": "John Doe",
    "emails": [
        {
            "email": "[email protected]",
            "is_primary": true,
            "is_verified": true
        }
    ],
    "is_sso_user": false,
    "default_group_guid": "ABCde1f23gh"
}

More...

If all else fails, there's always more Documentation.

Versions

Version
0.9.3
0.9.2