mapbox / mapbox-sdk-rb

A Ruby interface to Mapbox APIs.
Other
59 stars 32 forks source link

Warning: "URI.escape is obsolete" in Ruby 2.7 #47

Closed talsafran closed 3 years ago

talsafran commented 3 years ago

Hi friends 👋

I'm using the forward geocoding method and it's causing two warnings that URI.escape is obsolete:

> Mapbox::Geocoder.geocode_forward("netherlands", limit: 1, types: ["country"])

vendor/gems/2.7.1/ruby/2.7.0/gems/mapbox-sdk-2.3.0.1.gc3b22c8/lib/mapbox/geocoder.rb:42: warning: URI.escape is obsolete
vendor/gems/2.7.1/ruby/2.7.0/gems/mapbox-sdk-2.3.0.1.gc3b22c8/lib/mapbox.rb:81: warning: URI.escape is obsolete

=> [{"type"=>"FeatureCollection",
  "query"=>["netherlands"],
  "features"=>
   [{"id"=>"country.13545879598622050",
     "type"=>"Feature",
     "place_type"=>["country"],
     "relevance"=>1,
     "properties"=>{"wikidata"=>"Q55", "short_code"=>"nl"},
     "text"=>"Netherlands",
     "place_name"=>"Netherlands",
     "bbox"=>[3.33390071158434, 50.7503661060614, 7.22749998189678, 53.6436329908026],
     "center"=>[5.61349061168593, 51.9724664894952],
     "geometry"=>{"type"=>"Point", "coordinates"=>[5.61349061168593, 51.9724664894952]}}],
  "attribution"=>
   "NOTICE: © 2020 Mapbox and its suppliers. All rights reserved. Use of this data is subject to the Mapbox Terms of Service (https://www.mapbox.com/about/maps/). This response and the information it contains may not be retained. POI(s) provided by Foursquare."},
 {}]

Apparently this method was deprecated a long time ago and you should use URI.encode_www_form_component instead.

This blog post has more info on what to do: https://docs.knapsackpro.com/2020/uri-escape-is-obsolete-percent-encoding-your-query-string