<commit_before># bit.ly api client built in java

[ ![TravicCI](https://travis-ci.org/stackmagic/bitly-api-client.svg?branch=master) ](https://travis-ci.org/stackmagic/bitly-api-client)
[ ![Download](https://api.bintray.com/packages/stackmagic/maven/bitly-api-client/images/download.svg) ](https://bintray.com/stackmagic/maven/bitly-api-client/_latestVersion)

This is a simple java client for the [bit.ly v3 api](http://dev.bitly.com/api.html). It is:

* at version 0.8.0 (some deprecated calls from 0.7.x were removed)
* small
* easy to use
* fairly complete
* built with gradle
* reasonably bugfree
* with a minimum of dependencies
* licensed under the apache license 2.0

I use versions in the form of `x.y.z` - please do not expect compatibility if `x` or `y` has changed, if only `z` has changed there might be a chance that releases are compatible, the reason being that there is still a lot of refactoring going on and there will still be quite a bit of that for some time.

For information on the current feature-set have a look at the file `CHANGELOG`

# Get Involved!

If you want a feature/bugfix go ahead, fork this repo, make a fix (on the development branch) and send me a pull request! :)

# Get Started Right Away

## STEP 0: Get The Library

The lib is published on bintray and linked with the jcenter repository:
https://bintray.com/stackmagic/maven/bitly-api-client

### Gradle Setup

The [jcenter() shortcut requires at least gradle 1.7](http://www.gradle.org/docs/1.7/release-notes#jcenter-repository-support)

```groovy
buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'net.swisstech:bitly-api-client:+'
    }
}
```

### Maven Setup

```xml
<repository>
    <id>central</id>
    <name>bintray</name>
    <url>http://jcenter.bintray.com</url>
</repository>

<dependencies>
    <dependency>
        <groupId>net.swisstech</groupId>
        <artifactId>bitly-api-client</artifactId>
        <version>...</version>
    </dependency>
</dependencies>
```

## STEP 1: Get An OAuth Access Token (from bit.ly)

There is one prerequisite: you need to obtain an oauth access token from bit.ly (which also requires you to [have an account with bit.ly](https://bitly.com/a/sign_up) and [register an app in the dev center](http://bitly.com/a/settings/advanced)). You can do this with [scribe-java](https://github.com/fernandezpablo85/scribe-java) but bit.ly support is not yet available. I made a fork of the scribe project and added bit.ly support. A pull request is currently pending. In the mean time: use my fork (or just the `BitlyApi` class from it) which is available here: https://github.com/stackmagic/scribe-java.

## STEP 2: Check Out The Integration Tests

There are a bunch of integration tests that you can run and look at to get an idea of how this stuff works. The tests are all matching `**/*IntegrationTest.java` inside `src/test/java`.

In order to run the integration tests you must put your access token into a file with a single line and no leading or trailing spaces named `.accesstoken` inside the project's root directory.

Please note that some of the integration tests may fail for you since you don't have the correct access token and so you'll end up trying to manipulate some of "my" links which will of course fail, at least it should.

## STEP 3: Get Cracking (Fluent Builders)

The basic principle is simple: You create a BitlyClient with your access token. This is your factory and can be reused and passed around instead of passing around the access token String. Let the `BitlyClient` create a `RequestBuilder` for you and configure it, then make the call to bitly and work with the response. Simple, right? So here goes:<commit_msg>update way to get access token from bit.ly<commit_after># bit.ly api client built in java

[ ![TravicCI](https://travis-ci.org/stackmagic/bitly-api-client.svg?branch=master) ](https://travis-ci.org/stackmagic/bitly-api-client)
[ ![Download](https://api.bintray.com/packages/stackmagic/maven/bitly-api-client/images/download.svg) ](https://bintray.com/stackmagic/maven/bitly-api-client/_latestVersion)

This is a simple java client for the [bit.ly v3 api](http://dev.bitly.com/api.html). It is:

* at version 0.8.0 (some deprecated calls from 0.7.x were removed)
* small
* easy to use
* fairly complete
* built with gradle
* reasonably bugfree
* with a minimum of dependencies
* licensed under the apache license 2.0

I use versions in the form of `x.y.z` - please do not expect compatibility if `x` or `y` has changed, if only `z` has changed there might be a chance that releases are compatible, the reason being that there is still a lot of refactoring going on and there will still be quite a bit of that for some time.

For information on the current feature-set have a look at the file `CHANGELOG`

# Get Involved!

If you want a feature/bugfix go ahead, fork this repo, make a fix (on the development branch) and send me a pull request! :)

# Get Started Right Away

## STEP 0: Get The Library

The lib is published on bintray and linked with the jcenter repository:
https://bintray.com/stackmagic/maven/bitly-api-client

### Gradle Setup

The [jcenter() shortcut requires at least gradle 1.7](http://www.gradle.org/docs/1.7/release-notes#jcenter-repository-support)

```groovy
buildscript {
    repositories {
        jcenter()
    }

    dependencies {
        classpath 'net.swisstech:bitly-api-client:+'
    }
}
```

### Maven Setup

```xml
<repository>
    <id>central</id>
    <name>bintray</name>
    <url>http://jcenter.bintray.com</url>
</repository>

<dependencies>
    <dependency>
        <groupId>net.swisstech</groupId>
        <artifactId>bitly-api-client</artifactId>
        <version>...</version>
    </dependency>
</dependencies>
```

## STEP 1: Get An OAuth Access Token (from bit.ly)

https://support.bitly.com/hc/en-us/articles/230647907-How-do-I-find-my-OAuth-access-token-

## STEP 2: Check Out The Integration Tests

There are a bunch of integration tests that you can run and look at to get an idea of how this stuff works. The tests are all matching `**/*IntegrationTest.java` inside `src/test/java`.

In order to run the integration tests you must put your access token into a file with a single line and no leading or trailing spaces named `.accesstoken` inside the project's root directory.

Please note that some of the integration tests may fail for you since you don't have the correct access token and so you'll end up trying to manipulate some of "my" links which will of course fail, at least it should.

## STEP 3: Get Cracking (Fluent Builders)

The basic principle is simple: You create a BitlyClient with your access token. This is your factory and can be reused and passed around instead of passing around the access token String. Let the `BitlyClient` create a `RequestBuilder` for you and configure it, then make the call to bitly and work with the response. Simple, right? So here goes:
{'fraction_non_alphanumeric': 0.09683908045977012, 'fraction_numerical': 0.00617816091954023, 'mean_word_length': 3.9263977353149326, 'pattern_counts': {'":': 0, '<': 39, '<?xml version=': 0, '>': 39, 'https://': 14, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1902433', 'n_tokens_mistral': 2140, 'n_tokens_neox': 2039, 'n_words': 875}