Bitly Shortener for Kotlin, Java & Android https://github.com/ethauvin/bitly-shorten
Find a file
2024-05-19 12:39:44 -07:00
.circleci Bumped dependencies 2024-02-09 00:58:10 -08:00
.github/workflows Bumped workflow actions to the latest versions 2024-05-10 00:02:44 -07:00
.idea Implement custom bitlink update. Closes #15 2024-05-19 02:19:59 -07:00
config Implement custom bitlink update. Closes #15 2024-05-19 02:19:59 -07:00
docs Updated docs 2023-11-26 04:48:21 -08:00
examples Bumped Kotlin extension to version 0.9.5 2024-05-19 12:39:44 -07:00
lib/bld Bumped Kotlin extension to version 0.9.5 2024-05-19 12:39:44 -07:00
src Added return types to builders functions 2024-05-19 02:20:28 -07:00
.editorconfig Initial commit. 2020-02-25 13:51:54 -08:00
.gitattributes Initial commit. 2020-02-25 13:51:54 -08:00
.github_changelog_generator Updated dependencies 2023-04-20 02:35:23 -07:00
.gitignore Moved from Gradle to bld 2023-11-11 21:26:13 -08:00
.gitlab-ci.yml Fixed workflows/pipelines 2023-11-11 21:35:15 -08:00
bitbucket-pipelines.yml Fixed workflows/pipelines 2023-11-11 21:35:15 -08:00
bld Moved from Gradle to bld 2023-11-11 21:26:13 -08:00
bld.bat Moved from Gradle to bld 2023-11-11 21:26:13 -08:00
CHANGELOG.md Cleanup before 1.0 release 2023-09-25 16:11:49 -07:00
LICENSE.txt Updated copyright 2024-05-10 00:30:51 -07:00
pom.xml Bumped org.json to version 20240303 2024-05-10 00:14:30 -07:00
README.md Implement custom bitlink update. Closes #15 2024-05-19 02:19:59 -07:00
sonar-project.properties Moved from Gradle to bld 2023-11-11 21:26:13 -08:00

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

Quality Gate Status GitHub CI CircleCI

Bitly Shortener for Kotlin, Java & Android

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

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

bld

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

repositories = List.of(MAVEN_CENTRAL, SONATYPE_SNAPSHOTS_LEGACY);

scope(compile)
    .include(dependency("net.thauvin.erik:bitly-shorten:1.0.1"));

Be sure to use the bld Kotlin extension in your project.

Gradle, Maven, etc…

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:bitly-shorten:1.0.1")
}

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 CreateConfig.Builder("https://erik.thauvin.net/blog")
        .title("Erik's Weblog")
        .tags(new String[] { "blog", "weblog"})
        .build();

bitly.bitlinks().create(config);
var config = new UpdateConfig.Builder("https://bit.ly/380ojFd")
        .title("Erik's Weblog")
        .tags(new String[] { "blog", "weblog"})
        .build();

bitly.bitlinks().update(config);

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"
}

API Response & Endpoints

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)
} else {
    println("${response.message}: ${response.description} (${response.statusCode})")
}

Non-implemented API endpoints can also be called directly:

val response = bitly.call("/user", 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"
}

Contributing

If you want to contribute to this project, all you have to do is clone the GitHub repository:

git clone git@github.com:ethauvin/bitly-shorten.git

Then use bld to build:

cd bitly-shorten
./bld compile

The project has an IntelliJ IDEA project structure. You can just open it after all the dependencies were downloaded and peruse the code.

More…

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