Tinyurls in Langform erhalten

  • Impressum
  • Administration
  • Kontaktformular
  • Jabber
  • Tagcloud
  • Twitter
  • Soup
  • Github

roothausen

Tinyurls in Langform erhalten

22:02

Saturday, September 13. 2008

Bei vielen Diensten wie z.B. Twitter werden mittlerweile statt normalen URLs verkuerzte abgeschickt. Sollte man mal auf die Idee kommen diese wieder in Orginalform haben zu wollen, koennte man dazu fuer jeden der bekannten Dienste Methoden implementieren. Oder man benutzt die API des Dienstes longurl.com. Die Software dahinter wurde uebrigens unter der AGPL lizensiert und den SourceCode kann man hier ankucken.

Ich habe natuerlich gleich die Klasse fuer bit.ly erweitert:


#!/usr/bin/env ruby

# client class for url shortening service bit.ly and url expandig service longurl.com

require 'rubygems'
require 'net/http'
require 'uri'
require 'json'


class ShortURL
  def self.shortURL(url)
    api_url = "http://bit.ly/api"
    res = Net::HTTP.post_form(URI.parse(api_url),{'url'=> url})
    return res.body
  end

  def self.expandURL(url)
    api_url = "http://api.longurl.org/v1/expand?url=#{url}&format=json"
    res = Net::HTTP.get(URI.parse(api_url))
    data = JSON.parse(res)
   # if expanding url failed
    if data.has_key? 'messages'
      return url
    end
    return data["long_url"]
  end
end
 

Somit lassen sich mit der Methode ShortURL.expandURL(uri) URLs auch verlaengern.

Zusaetzlich gibt es fuer diesen Dienst noch eine Firefox Erweiterung und ein Greasemonkey Script um die langen URLs in Tooltips darzustellen.

Posted by Sven Pfleiderer in computer, web | Comments (0) | Trackbacks (0)
Defined tags for this entry: code, computer, programming, ruby, software, web
Related entries by tags:
  • Mobile devices or: How I Learned to Stop Worrying and Love the iOS
  • The VP8 Video Codec
  • My Bachelor Thesis: Scale the realtime web
  • Distributed contact management using HTTP
  • Gesichtserkennung/Eigenfaces
< OTR mit PSI | Arrr >

Trackbacks
Trackback specific URI for this entry

No Trackbacks

Comments
Display comments as (Linear | Threaded)

No comments

Add Comment

Standard emoticons like :-) and ;-) are converted to images.
E-Mail addresses will not be displayed and will only be used for E-Mail notifications.

To prevent automated Bots from commentspamming, please enter the string you see in the image below in the appropriate input box. Your comment will only be submitted if the strings match. Please ensure that your browser supports and accepts cookies, or your comment cannot be verified correctly.
CAPTCHA

You can use [geshi lang=lang_name [,ln={y|n}]][/geshi] tags to embed source code snippets.
Markdown format allowed
 
 

JavaScript String .fromCharCode

Calendar

« May '12 »
Mo Tu We Th Fr Sa Su
  1 2 3 4 5 6
7 8 9 10 11 12 13
14 15 16 17 18 19 20
21 22 23 24 25 26 27
28 29 30 31      

Quicksearch

Kategorien

  • XML computer
  • XML misc
  • XML web
  • XML zeitgeist


All categories

Archiv

  • May 2012
  • April 2012
  • March 2012
  • February 2012
  • January 2012
  • Recent...
  • Older...

Feeds

  • XML RSS 2.0 feed
  • ATOM/XML ATOM 1.0 feed
  • XML RSS 2.0 Comments

Links

Retinacast
Shackspace
Yaxim
Radio Tux
Kais Blog
Blumen Pfleiderer
Alk
paxos
filzo
Marc Seeger
polzifer
Moritz Haarmann

Tags

android bad world blog blogging browser changes code comic computer contentmanagement encryption feedreader firefox free fun google gui hardware howto html im jabber java life lighttpd linux linux&unix markup media misc mobile murphy networking newsbeuter opensource picture politics presentation privacy programming regular expression rss ruby s9y scala screenshot sdk security server shortys software stuff tail -f /var/log/life test tool tv unix video web webdesign webwide windows xml zeitgeist

Lizenz

Creative Commons License - Some Rights Reserved