Skip to content
Snippets Groups Projects
Commit ca5d7813 authored by Marcin Olichwirowicz's avatar Marcin Olichwirowicz
Browse files

Extracts json parsing method

parent 1c0dd3e4
No related branches found
No related tags found
No related merge requests found
......@@ -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" : "")
......
......@@ -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 # ---------------------------------------------------------------
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment