gem install bitly-shortener
OR in Gemfile:
gem 'bitly-shortener'
- Generate your https://bit.ly access token from here
- Set the token obtained in 1 above as your
BITLY_API_KEY
You can use this within your app or via the CLI.
Code:
url = Bitly::Shortener::Request.new('https://www.wsj.com/articles/covid-upended-americans-finances-just-not-in-the-ways-we-expected-11609081200')
shortened_url = Bitly::Shortener::Shorten.new(url).shortened_url
pp shortened_url # => https://on.wsj.com/2MiuBuo
CLI:
$ bin/shorten -l https://www.wsj.com/articles/covid-upended-americans-finances-just-not-in-the-ways-we-expected-11609081200
https://on.wsj.com/2MiuBuo/app
$