class Owly::Shortener

Public Class Methods

shorten(key, url, options={}) click to toggle source
# File lib/owly.rb, line 6
def self.shorten(key, url, options={})
  response = HTTParty.get("http://ow.ly/api/1.1/url/shorten?apiKey=#{key}&longUrl=#{url}")
  json = JSON.parse(response.body)
  shortUrl = CGI::unescape(json['results']['shortUrl'])
  if options[:base_url]
    shortUrl = shortUrl.sub('http://ow.ly', options[:base_url])
  end
  return shortUrl
end