Git Product home page Git Product logo

ruby-bitly's Introduction

A simple bit.ly ruby client.

<img src=“https://travis-ci.org/dx7/ruby-bitly.svg?branch=master” alt=“Build Status” /> <img src=“https://codeclimate.com/github/dx7/ruby-bitly/badges/gpa.svg” />

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

ruby-bitly's People

Contributors

dependabot[bot] avatar dx7 avatar p avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

ruby-bitly's Issues

Gemfile (Ruby 1.9.2)

Hi!

I want to use your gem by adding it to Gemfile. I get this error...

There was a LoadError while evaluating ruby-bitly.gemspec:
  no such file to load -- restclient from
  /Users/otobrglez/.rvm/gems/ruby-1.9.2-p180@sveze-jabolko/bundler/gems/ruby-bitly-4dbe5d70f0db/ruby-bitly.gemspec:3:in `<main>'

Does it try to require a relative path? That doesn't work in Ruby 1.9.

My Gemfile:

gem 'ruby-bitly', :git => 'git://github.com/rafaeldx7/ruby-bitly.git', :require => 'ruby-bitly'

Have a nice day and thanks for your work ;)

  • Oto

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.