- Notifications
You must be signed in to change notification settings - Fork4
A simple bit.ly ruby client to shorten URLs, expand or get number of clicks on a bitlink.
License
NotificationsYou must be signed in to change notification settings
dx7/ruby-bitly
Folders and files
Name | Name | Last commit message | Last commit date | |
---|---|---|---|---|
Repository files navigation
<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” />
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 belowendOr set them individualy:Bitly.login = 'login-here'Bitly.api_key = 'api-key-here'Bitly.use_ssl = false # read more belowBitly.proxy = 'http://localhost:8888' # read more belowOr set them on methods if you prefer (see it below).
bitly =Bitly.shorten(long_url:"https://dx7.github.io/")# setting credentials or a custom domainbitly =Bitly.shorten(long_url:"https://dx7.github.io/",domain:"my.do",login:"login-here",api_key:"api-key-here")# resultbitly.short_url#=> "http://bit.ly/2dAjjfo"bitly.long_url#=> "https://dx7.github.io/"bitly.new_hash?#=> truebitly.global_hash#=> "2dAkyet"bitly.user_hash#=> "2dAjjfo"bitly.success?#=> true
bitly =Bitly.expand(short_url:"http://bit.ly/2dAjjfo")# setting credentialsbitly =Bitly.expand(short_url:"http://bit.ly/2dAjjfo",login:"login-here",api_key:"api-key-here")# resultbitly.short_url#=> "http://bit.ly/2dAjjfo"bitly.long_url#=> "https://dx7.github.io/"bitly.global_hash#=> "2dAkyet"bitly.user_hash#=> "2dAjjfo"bitly.success?#=> true
bitly =Bitly.get_clicks(short_url:"http://bit.ly/2dAjjfo")# setting credentialsbitly =Bitly.get_clicks(short_url:"http://bit.ly/2dAjjfo",login:"login-here",api_key:"api-key-here")# resultbitly.short_url#=> "http://bit.ly/2dAjjfo"bitly.user_hash#=> "2dAjjfo"bitly.global_hash#=> "2dAkyet"bitly.user_clicks#=> 0bitly.global_clicks#=> 1bitly.success?#=> true
# if something goes wrong you can checkbitly.success?#=> falsebitly.error#=> 'INVALID_LOGIN'
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'
AllcallswilluseSSLbydefault.Youcandisableit:Bitly.use_ssl =false
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
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.ioOr you can create the file ~/.bitly with that content: login: <login-here> api_key: <api-key-here>
dx7 ~ dx7(a)protonmail.ch
Copyright (c) 2010 dx7. Licensed under the MIT License:http://www.opensource.org/licenses/mit-license.php
About
A simple bit.ly ruby client to shorten URLs, expand or get number of clicks on a bitlink.
Topics
Resources
License
Stars
Watchers
Forks
Packages0
No packages published