Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 27 lines (26 sloc) 0.785 kb
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
# Copyright (c) 2011, David Morley. This file is
# licensed under the Affero General Public License version 3 or later. See
# the COPYRIGHT file.

module Morley
module Shorty
 def self.swap(message)
require 'net/http'
require 'uri'
require 'rubygems'
    message.gsub!(/( |^)(www\.[^\s]+\.[^\s])/, '\1http://\2')
    message.gsub!(/(<a target="\\?_blank" href=")?(https|http|ftp):\/\/\/([^\s]+)/) do |m|
      if !$1.nil?
        m
      else
        #do
        oldurl = CGI::escape("#{$2}://#{$3}")
        newurl = Net::HTTP.get(URI.parse("http://dia.so/diaspora-api.php?action=shorturl&url=#{oldurl}&format=simple&signature=d388503621"))
        res = %{#{newurl}}
        res.gsub!(/(\*|_)/) { |m| "\\#{$1}" }
        res
      end
    end
    return message
end
end
end
Something went wrong with that request. Please try again.