diff --git a/lib/geocoder/lookups/base.rb b/lib/geocoder/lookups/base.rb index 6589345a35260f70322ad0b01e2b6955bb97ba0a..c0ef4682fb8484bfb213488b344b6b9e7a6bc27f 100644 --- a/lib/geocoder/lookups/base.rb +++ b/lib/geocoder/lookups/base.rb @@ -171,22 +171,26 @@ module Geocoder "(use Geocoder.configure(:timeout => ...) to set limit)." end + def parse_json(data) + if defined?(ActiveSupport::JSON) + ActiveSupport::JSON.decode(data) + else + JSON.parse(data) + end + end + ## # Parses a raw search result (returns hash or array). # def parse_raw_data(raw_data) - if defined?(ActiveSupport::JSON) - ActiveSupport::JSON.decode(raw_data) - else - JSON.parse(raw_data) - end + parse_json(raw_data) rescue warn "Geocoding API's response was not valid JSON." end ## # Protocol to use for communication with geocoding services. - # Set in configuration but not available for every service. + # Set in configuration but no available for every service. # def protocol "http" + (configuration.use_https ? "s" : "") diff --git a/lib/geocoder/lookups/google.rb b/lib/geocoder/lookups/google.rb index 65308de2a305e0968502f35a587957cc00e6600c..4daeb977f3f0aa8cd71c281e2a9e82517f5a19af 100644 --- a/lib/geocoder/lookups/google.rb +++ b/lib/geocoder/lookups/google.rb @@ -17,7 +17,7 @@ module Geocoder::Lookup end def valid_response(response) - super(response) && JSON.parse(response.body)["status"] == "OK" + super(response) && parse_json(response.body)["status"] == "OK" end private # ---------------------------------------------------------------