Bitly Shortener for Kotlin, Java & Android https://github.com/ethauvin/bitly-shorten
Find a file
2020-03-17 17:01:31 -07:00
.circleci Added CI configs. 2020-02-25 18:34:01 -08:00
.idea Updated dependencies. 2020-03-17 17:01:31 -07:00
config Added dokkaDocs 2020-03-03 00:29:30 -08:00
docs Removed toJson() in CallResponse. 2020-03-17 17:01:09 -07:00
examples Updated dependencies. 2020-03-17 17:01:31 -07:00
gradle/wrapper Updated dependencies. 2020-03-17 17:01:31 -07:00
src Removed toJson() in CallResponse. 2020-03-17 17:01:09 -07:00
.editorconfig Initial commit. 2020-02-25 13:51:54 -08:00
.gitattributes Initial commit. 2020-02-25 13:51:54 -08:00
.gitignore Added CallResponse docs. 2020-03-03 21:54:24 -08:00
.travis.yml Added pom. 2020-02-25 19:22:16 -08:00
build.gradle.kts Updated dependencies. 2020-03-17 17:01:31 -07:00
detekt-baseline.xml Added CallResponse and Bitlinks.update(). 2020-03-03 13:49:58 -08:00
gradlew Fixed .gitignore 2020-02-25 16:01:42 -08:00
gradlew.bat Initial commit. 2020-02-25 13:51:54 -08:00
LICENSE.txt Added license. 2020-02-25 18:33:42 -08:00
pom.xml Updated dependencies. 2020-03-17 17:01:31 -07:00
README.md Removed toJson() in CallResponse. 2020-03-17 17:01:09 -07:00
settings.gradle.kts Added buildScan plugin. 2020-02-26 01:50:58 -08:00
version.properties Updated dependencies. 2020-03-17 17:01:31 -07:00

License (3-Clause BSD)
Known Vulnerabilities Quality Gate Status Build Status CircleCI

Bitly Shortener for Kotlin/Java.

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("http://bit.ly/380ojFd")

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

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

// Update a bitlink
bitly.bitlinks().update("http://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

JSON

All implemented methods can return the full API JSON responses:

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

Non-implemented methods 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": "john@doe.com",
            "is_primary": true,
            "is_verified": true
        }
    ],
    "is_sso_user": false,
    "default_group_guid": "ABCde1f23gh"
}

More...

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