Skip to content
Snippets Groups Projects
Commit 7b2db0ec authored by Alex Reisner's avatar Alex Reisner
Browse files

Fix Ruby 1.9 and JRuby compatibility.

Remove json gem dependency and mention json_pure as alternative.
parent bf911edd
No related branches found
No related tags found
No related merge requests found
......@@ -11,5 +11,4 @@ Gem::Specification.new do |s|
s.description = "Provides object geocoding (by street or IP address), reverse geocoding (coordinates to street address), and distance calculations for geocoded objects. Designed for Rails but works with other frameworks too."
s.files = `git ls-files`.split("\n") - %w[geocoder.gemspec Gemfile init.rb]
s.require_paths = ["lib"]
s.add_dependency 'json', '>= 1.0.0'
end
require 'net/http'
unless defined? ActiveSupport::JSON
unless defined?(ActiveSupport::JSON)
begin
require 'json'
rescue LoadError
raise LoadError, "Please install the json gem to parse geocoder results."
raise LoadError, "Please install the 'json' or 'json_pure' gem to parse geocoder results."
end
end
......@@ -67,17 +67,14 @@ module Geocoder
# Parses a raw search result (returns hash or array).
#
def parse_raw_data(raw_data)
if defined?(JSON) and defined?(JSON.parse)
if defined?(ActiveSupport::JSON)
ActiveSupport::JSON.decode(raw_data)
else
begin
JSON.parse(raw_data)
rescue
warn "Geocoding API's response was not valid JSON."
end
elsif defined?(ActiveSupport::JSON)
ActiveSupport::JSON.decode(raw_data)
else
raise Geocoder::Error, "No JSON-parsing library found. " +
"Please install either the 'json' or 'activesupport' gem."
end
end
......
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