lib/onebox/engine/google_maps_onebox.rb in onebox-2.2.14 vs lib/onebox/engine/google_maps_onebox.rb in onebox-2.2.15

- old
+ new

@@ -117,12 +117,10 @@ zoom = match[:zoom].to_f.round @url = "https://www.google.com/maps/embed?pb=!3m2!2sen!4v0!6m8!1m7!1s#{panoid}!2m2!1d#{lon}!2d#{lat}!3f#{heading}!4f#{pitch}!5f#{fov}" @placeholder = "https://maps.googleapis.com/maps/api/streetview?size=690x400&location=#{lon},#{lat}&pano=#{panoid}&fov=#{zoom}&heading=#{heading}&pitch=#{pitch}&sensor=false" when :canonical - uri = URI(@url) - query = URI::decode_www_form(uri.query).to_h if !query.has_key?("ll") raise ArgumentError, "canonical url lacks location argument" unless query.has_key?("sll") query["ll"] = query["sll"] @url += "&ll=#{query["sll"]}" @@ -161,17 +159,23 @@ uri.path = uri.path.sub(/(?<=^\/maps\/d\/)\w+$/, target) uri.to_s end def follow_redirect! - uri = URI(@url) begin - http = Net::HTTP.start(uri.host, uri.port, - use_ssl: uri.scheme == 'https', open_timeout: timeout, read_timeout: timeout) - response = http.head(uri.path) + http = Net::HTTP.start( + uri.host, + uri.port, + use_ssl: uri.scheme == 'https', + open_timeout: timeout, + read_timeout: timeout + ) + response = http.head(uri.path) raise "unexpected response code #{response.code}" unless %w(200 301 302).include?(response.code) + @url = response.code == "200" ? uri.to_s : response["Location"] + @uri = URI(@url) ensure http.finish rescue nil end end end