All Projects → dx7 → ruby-bitly

dx7 / ruby-bitly

Licence: MIT license
A simple bit.ly ruby client to shorten URLs, expand or get number of clicks on a bitlink.

Programming Languages

ruby
36898 projects - #4 most used programming language

Projects that are alternatives of or similar to ruby-bitly

gShort
URL Shortener without all the crap
Stars: ✭ 80 (+370.59%)
Mutual labels:  shortener, bitly, shorten-urls
YOURLS
🔗 The de facto standard self hosted URL shortener in PHP
Stars: ✭ 9,007 (+52882.35%)
Mutual labels:  shortener, bitly, shorten-urls
urlshortener-rs
A very-very simple url shortener for Rust
Stars: ✭ 34 (+100%)
Mutual labels:  shortener, bitly, shorten-urls
bifrost
🌉 The rainbow bridge. URL shortener for Vercel.
Stars: ✭ 28 (+64.71%)
Mutual labels:  shortener, shorten-urls
ursho
URL Shortener Service in Go
Stars: ✭ 118 (+594.12%)
Mutual labels:  shortener, shorten-urls
ShortURL-Services-List
A list of 600+ URL shorteners (i.e goo.gl, bit.ly)
Stars: ✭ 32 (+88.24%)
Mutual labels:  bitly, shorturl
urlzap
⚡️ Your own static URL shortener
Stars: ✭ 57 (+235.29%)
Mutual labels:  shortener, shorten-urls
small-sh
Um encurtador de URL's gratuito e Open source. Torne suas URL's um tanto pequenas forma rápida e gratuita
Stars: ✭ 30 (+76.47%)
Mutual labels:  shortener, shorten-urls
bitly-vuejs
An URL shortener made with Bitly API, VueJS and ChuckCSS
Stars: ✭ 23 (+35.29%)
Mutual labels:  bitly, shorten-urls
1y
A template project to build a short URL manager with Eleventy
Stars: ✭ 68 (+300%)
Mutual labels:  shorten-urls, shorturl
ksana.in
✂️ Layanan pemendek tautan yang mudah, gratis & tanpa iklan
Stars: ✭ 186 (+994.12%)
Mutual labels:  shortener
laravel-bitly
Laravel package for generating bitly url
Stars: ✭ 72 (+323.53%)
Mutual labels:  bitly
goshort
Golang URL Shortener
Stars: ✭ 26 (+52.94%)
Mutual labels:  shortener
yii2-minify-url
Project on YII2 framework for create short url (url shortener)
Stars: ✭ 15 (-11.76%)
Mutual labels:  shortener
UrlShortener
Shortens long urls. Select from a list of available hosts.
Stars: ✭ 49 (+188.24%)
Mutual labels:  shorturl
bili-short-url
哔哩哔哩短链生成器。将B站站内链接转化为Bilibili短链,例如:https://b23.tv/F78kbY
Stars: ✭ 38 (+123.53%)
Mutual labels:  shorturl
snip
✌️ The simple, no-bs link shortener
Stars: ✭ 33 (+94.12%)
Mutual labels:  shortener
tinyurl-client
Easily use TinyURL in your JavaScript app. This library is no longer maintained.
Stars: ✭ 23 (+35.29%)
Mutual labels:  shorten-urls
node-bypasser
Bypass URL shortener websites
Stars: ✭ 33 (+94.12%)
Mutual labels:  shortener
kzilla.xyz
Shorten the URL. Broaden the reach.
Stars: ✭ 34 (+100%)
Mutual labels:  bitly

A simple bit.ly ruby client.

Build Status

Configuration

Loading the gem:

require 'ruby-bitly'

Set global configuration:

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

Or set them individualy:

Bitly.login   = 'login-here'
Bitly.api_key = 'api-key-here'
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).

Shortening a long URL

bitly = Bitly.shorten(long_url: "https://dx7.github.io/")

# setting credentials or a custom domain
bitly = Bitly.shorten(long_url: "https://dx7.github.io/", domain: "my.do", login: "login-here", api_key: "api-key-here")

# result
bitly.short_url   #=> "http://bit.ly/2dAjjfo"
bitly.long_url    #=> "https://dx7.github.io/"
bitly.new_hash?   #=> true
bitly.global_hash #=> "2dAkyet"
bitly.user_hash   #=> "2dAjjfo"
bitly.success?    #=> true

Expanding a Bitly URL

bitly = Bitly.expand(short_url: "http://bit.ly/2dAjjfo")

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

# result
bitly.short_url   #=> "http://bit.ly/2dAjjfo"
bitly.long_url    #=> "https://dx7.github.io/"
bitly.global_hash #=> "2dAkyet"
bitly.user_hash   #=> "2dAjjfo"
bitly.success?    #=> true

Getting Clicks from a Bitly URL

bitly = Bitly.get_clicks(short_url: "http://bit.ly/2dAjjfo")

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

# result
bitly.short_url      #=> "http://bit.ly/2dAjjfo"
bitly.user_hash      #=> "2dAjjfo"
bitly.global_hash    #=> "2dAkyet"
bitly.user_clicks    #=> 0
bitly.global_clicks  #=> 1
bitly.success?       #=> true

Error handling

# if something goes wrong you can check
bitly.success? #=> false
bitly.error    #=> 'INVALID_LOGIN'

Proxy

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'

SSL

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: http://bit.ly/a/sign_up.
  -k, --api-key KEY                You can find your api key here: http://bit.ly/a/your_api_key.

  -d, --domain DOMAIN              The short domain to use: either bit.ly, j.mp, bitly.com 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 for command line:
  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

Authentication

bit.ly API requires authentication credentials. You can get it on bit.ly[https://app.bitly.com/Ba48fIHfOg5/bitlinks/2Q1GQcD?actions=accountMain&actions=settings&actions=advancedSettings&actions=apiSupport].

Using commmand line you can supply credentials as parameters. For example:
  bitly -l <login-here> -k <api-key-here> -s http://dx7.github.io

Or you can create the file ~/.bitly with that content:
  login: <login-here>
  api_key: <api-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
Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].