add classic google maps onebox

This commit is contained in:
Régis Hanol 2013-11-28 19:23:11 +01:00
parent 488e9ca9dd
commit 47e1f1d1fe
1 changed files with 26 additions and 0 deletions

View File

@ -0,0 +1,26 @@
require 'net/http'
require_dependency 'oneboxer/base_onebox'
module Oneboxer
class ClassicGoogleMapsOnebox < BaseOnebox
matcher /^(https?:)?\/\/(maps\.google\.[\w.]{2,}|goo\.gl)\/maps?.+$/
def onebox
@url = get_long_url(@url) if @url.include?("//goo.gl/maps/")
"<iframe src='#{@url}&output=embed' width='690px' height='400px' frameborder='0' style='border:0'></iframe>" if @url.present?
end
def get_long_url(url)
uri = URI(url)
http = Net::HTTP.start(uri.host, uri.port)
http.open_timeout = 1
http.read_timeout = 1
response = http.head(uri.path)
response["Location"] if response.code == "301"
rescue
nil
end
end
end