A simple bit.ly ruby client.

<img src=“https://codeclimate.com/github/dx7/ruby-bitly/badges/gpa.svg” />

Shorten

require 'ruby-bitly'

# old way (deprecated)
bitly = Bitly.shorten("https://dx7.github.io/", "login-here", "key-here")

# new way
bitly = Bitly.shorten(long_url: "https://dx7.github.io/", login: "login-here", api_key: "key-here")

bitly.url #=> "http://bit.ly/2dAjjfo"

y bitly
  :long_url: http://dx7.github.io/
  :url: http://bit.ly/2dAjjfo
  :hash: 2dAjjfo
  :global_hash: micSj7
  :new_hash: 0
  :hash_path: 2dAjjfo
  :status_code: 200
  :status_txt: OK

Expand

require 'ruby-bitly'

# old way (deprecated)
bitly = Bitly.expand("http://bit.ly/2dAjjfo", "login-here", "key-here")

# new way
bitly = Bitly.expand(short_url: "http://bit.ly/2dAjjfo", login: "login-here", api_key: "key-here")

y bitly
  :short_url: http://bit.ly/2dAjjfo
  :long_url: https://dx7.github.io/
  :user_hash: 2dAjjfo
  :global_hash: 2dAkyet
  :status_code: 200
  :status_txt: OK

Get Clicks

require 'ruby-bitly'

# old way (deprecated)
bitly = Bitly.get_clicks("http://bit.ly/2dAjjfo", "login-here", "key-here")

# new way
bitly = Bitly.get_clicks(short_url: "http://bit.ly/2dAjjfo", login: "login-here", api_key: "key-here")

y bitly
  :short_url: https://bit.ly/2dAjjfo
  :global_hash: 2dAkyet
  :user_clicks: 0
  :user_hash: 2dAjjfo
  :global_clicks: 0
  :status_code: 200
  :status_txt: OK

Command Line Examples

Usage
  bitly [options] url

  For help: bitly -h

Basic examples:
  bitly -s http://dx7.github.io
  bitly -e http://bit.ly/2dAjjfo
  bitly --user-clicks http://bit.ly/2dAjjfo
  bitly --global-clicks http://bit.ly/2dAjjfo

Other examples:
  bitly -q -s http://dx7.github.io
  bitly --verbose -e http://bit.ly/2dAjjfo

Options
  -s, --shorten        Shorten a long url (default option)
  -e, --expand         Expand a short bitly url
  -u, --user-clicks    Show user clicks from the short bitly url
  -g, --global-clicks  Show global clicks from the short bitly url

  -l, --login LOGIN    Your bit.ly login
  -k, --key KEY        Your bit.ly API key

  -h, --help           Displays help message, then exit
  -v, --version        Display the version, then exit
  -q, --quiet          Output as little as possible, overrides verbose
  -V, --verbose        Verbose output

Authentication

bit.ly API requires authentication credentials.

You need a free bit.ly user account and apiKey. Signup at: http://bit.ly/a/sign_up
If you already have an account, you can find your apiKey at: http://bit.ly/a/your_api_key

You can supply credentials as parameters. For example:
  bitly -l <username> -k <key-here> -s http://dx7.github.io

Or you can create the file ~/.bitly (YAML format) with this content:
  login: <username>
  key: <key-here>

Author

dx7 ~ dx7(a)protonmail.ch
Copyright (c) 2010 dx7. Licensed under the MIT License:
http://www.opensource.org/licenses/mit-license.php