Class: BcmsBitly::ShortLink

Inherits:
ActiveRecord::Base
  • Object
show all
Defined in:
app/models/bcms_bitly/short_link.rb

Instance Method Summary collapse

Instance Method Details

#shorten(url) ⇒ Object

Turn a URL into a shorter Bitly URL

url - A String URL

Examples

shorten('http://www.google.com')

Returns the shortened URL String



18
19
20
21
22
23
24
# File 'app/models/bcms_bitly/short_link.rb', line 18

def shorten(url)
  Bitly.use_api_version_3
  username = BcmsBitly::Engine.config.bitly_username
  api_key  = BcmsBitly::Engine.config.bitly_api_key
  bitly    = Bitly.new(username, api_key)
  bitly.shorten(url).short_url
end