Class: ShortLink

Inherits:
Object
  • Object
show all
Defined in:
lib/short_link.rb

Class Method Summary collapse

Class Method Details


5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/short_link.rb', line 5

def self.shorten_link(link)
  Bitly.use_api_version_3
  bitly = Bitly.new('hospitium',ENV['BITLY_API'])
  page_url = bitly.shorten(link)
  short_url = page_url.short_url
  #fall back to tinyurl if bitly fails
  if short_url.blank?
    short_url = RestClient.get "https://tinyurl.com/api-create.php?url=#{link}"
  end
  
  short_url
end