From 47e1f1d1fecaeeb69c0e3a8e33fda95025a7b714 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9gis=20Hanol?= Date: Thu, 28 Nov 2013 19:23:11 +0100 Subject: [PATCH] add classic google maps onebox --- lib/oneboxer/classic_google_maps_onebox.rb | 26 ++++++++++++++++++++++ 1 file changed, 26 insertions(+) create mode 100644 lib/oneboxer/classic_google_maps_onebox.rb diff --git a/lib/oneboxer/classic_google_maps_onebox.rb b/lib/oneboxer/classic_google_maps_onebox.rb new file mode 100644 index 00000000000..e13f874528a --- /dev/null +++ b/lib/oneboxer/classic_google_maps_onebox.rb @@ -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/") + "" 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