Sha256: 0725b8993c1bcbbe19c192eb35ea71d21e70114f75bd4520aaec1ff0a1729a17
Contents?: true
Size: 1.24 KB
Versions: 2
Compression:
Stored size: 1.24 KB
Contents
module Onebox module Engine class ClassicGoogleMapsOnebox include Engine include LayoutSupport matches_regexp /^(https?:)?\/\/((maps|www)\.google\.[\w.]{2,}|goo\.gl)\/maps?.+$/ def url @url = get_long_url if @url.include?("//goo.gl/maps/") @url = get_canonical_url if @url.include?("www.google") @url end def to_html "<iframe src='#{url}&output=embed' width='690px' height='400px' frameborder='0' style='border:0'></iframe>" end private def data {link: url, title: url} end def get_canonical_url uri = URI(@url) http = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == 'https') http.open_timeout = timeout http.read_timeout = timeout response = http.head(uri.path) response["Location"].sub(/&?output=classic/, '') if response.code == "302" rescue @url end def get_long_url uri = URI(@url) http = Net::HTTP.start(uri.host, uri.port) http.open_timeout = timeout http.read_timeout = timeout response = http.head(uri.path) response["Location"] if response.code == "301" rescue @url end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
onebox-1.5.14 | lib/onebox/engine/classic_google_maps_onebox.rb |
onebox-1.5.13 | lib/onebox/engine/classic_google_maps_onebox.rb |