2 Replies - 1550 Views - Last Post: 20 April 2010 - 12:44 PM

#1 erik.price   User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

URL Shrinker

Posted 09 December 2009 - 06:39 AM

Description: Uses is.gd (although you could edit it to use basically any service that provides some form of API) to return a smaller URL of a site given
require 'open-uri'

def shrinkURL(addr)
  result = ''                                     #to store the resulting address
  host = 'http://is.gd'                   #base site. I orginally tried tinyURL, but they appear 
                                                     #to have changed the way the API is used without 
                                                     #documenting it, or discontinued it
  apiPath = '/api.php?longurl='       #path to API call that creates the url
  tinyPath = apiPath+addr                   #adds the site to the API call
  
  open(host+tinyPath) do |page|
    result = page.read
  end
  
  return result
  
end


#Example:
puts shrinkURL("dreamincode.net") #=>http://is.gd/5gTOU try it out! 


Is This A Good Question/Topic? 0
  • +

Replies To: URL Shrinker

#2 MitkOK   User is offline

  • D.I.C Regular
  • member icon

Reputation: 32
  • View blog
  • Posts: 403
  • Joined: 09-August 07

Re: URL Shrinker

Posted 20 April 2010 - 09:15 AM

It's not idiomatic to use camel case for variables.
Was This Post Helpful? 0
  • +
  • -

#3 erik.price   User is offline

  • D.I.C Lover
  • member icon

Reputation: 486
  • View blog
  • Posts: 2,690
  • Joined: 18-December 08

Re: URL Shrinker

Posted 20 April 2010 - 12:44 PM

True. Apparently I was stuck in a Java style when writing this.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1