Fetching contributors…
Cannot retrieve contributors at this time
162 lines (112 sloc) 4.63 KB

A simple ruby client.



You need to load the gem:

require 'ruby-bitly'

Set global configuration:

Bitly.config do |c|
  c.login   = 'login-here'
  c.api_key = 'key-here'
  c.key     = 'key-here' # deprecated: use api_key instead
  c.use_ssl = false # read more below
  c.proxy   = 'http://localhost:8888' # read more below

Or set them individualy:

Bitly.login   = 'login-here'
Bitly.api_key = 'key-here'
Bitly.key     = 'key-here' # deprecated: use api_key instead
Bitly.use_ssl = false # read more below
Bitly.proxy   = 'http://localhost:8888' # read more below

Or set them on methods if you prefer (see it below).


# old way
bitly = Bitly.shorten("")

# old way setting local configuration
bitly = Bitly.shorten("", "login-here", "key-here")

# new way
bitly = Bitly.shorten(url: "")

# new way setting local configuration
bitly = Bitly.shorten(url: "", login: "login-here", api_key: "key-here", domain: "")

# result
bitly.url #=> ""

y bitly
  :hash: 2dAjjfo
  :global_hash: micSj7
  :new_hash: 0
  :hash_path: 2dAjjfo
  :status_code: 200
  :status_txt: OK


# old way
bitly = Bitly.expand("")

# old way setting local configuration
bitly = Bitly.expand("", "login-here", "key-here")

# new way
bitly = Bitly.expand(url: "")

# new way setting local configuration
bitly = Bitly.expand(url: "", login: "login-here", api_key: "key-here")

# result
y bitly
  :user_hash: 2dAjjfo
  :global_hash: 2dAkyet
  :status_code: 200
  :status_txt: OK

Get Clicks

# old way
bitly = Bitly.get_clicks("")

# old way setting local configuration
bitly = Bitly.get_clicks("", "login-here", "key-here")

# new way
bitly = Bitly.get_clicks(url: "")

# new way setting local configuration
bitly = Bitly.get_clicks(url: "", login: "login-here", api_key: "key-here")

# result
y bitly
  :global_hash: 2dAkyet
  :user_clicks: 0
  :user_hash: 2dAjjfo
  :global_clicks: 0
  :status_code: 200
  :status_txt: OK


All calls will use the proxy specified by environment variable "http_proxy" by default.

You can set the proxy directly if you prefer:

Bitly.proxy = 'http://localhost:8888'


All calls will use SSL by default. You can disable it:

Bitly.use_ssl = false

Command Line

Usage: bitly [options] URL
  -l, --login LOGIN                You need a free Bitly login and api key. Sign up here:
  -k, --key KEY                    You can find your api key here:

  -d, --domain DOMAIN              The short domain to use: either,, or a custom short domain.
                                   This option will override the default short domain selected in your Bitly account settings.

  -s, --shorten                    Given a long URL, returns a Bitlink.
  -e, --expand                     Given a Bitlink, hash or custom path, returns the target (long) URL.
  -u, --user-clicks                The total count of clicks to this user's Bitlink.
  -g, --global-clicks              The total count of the corresponding Bitly aggregate hash.

  -h, --help                       Print this help.
  -v, --version                    Print version.

Basic examples:
  bitly -s
  bitly -e
  bitly --user-clicks
  bitly --global-clicks

Authentication API requires authentication credentials.

Using commmand line you can supply credentials as parameters. For example:
  bitly -l <login-here> -k <key-here> -s

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


dx7 ~ dx7(a)


Copyright (c) 2010 dx7. Licensed under the MIT License: