lib/geocoder/lookups/base.rb in geocoder-1.1.0 vs lib/geocoder/lookups/base.rb in geocoder-1.1.1

- old
+ new

@@ -118,18 +118,18 @@ ## # 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 - begin + begin + if defined?(ActiveSupport::JSON) + ActiveSupport::JSON.decode(raw_data) + else JSON.parse(raw_data) - rescue - warn "Geocoding API's response was not valid JSON." end + rescue + warn "Geocoding API's response was not valid JSON." end end ## # Protocol to use for communication with geocoding services. @@ -144,18 +144,19 @@ # def fetch_raw_data(query, reverse = false) timeout(Geocoder::Configuration.timeout) do url = query_url(query, reverse) uri = URI.parse(url) - unless cache and response = cache[url] + unless cache and body = cache[url] client = http_client.new(uri.host, uri.port) client.use_ssl = true if Geocoder::Configuration.use_https - response = client.get(uri.request_uri).body - if cache - cache[url] = response + response = client.get(uri.request_uri) + body = response.body + if cache and (200..399).include?(response.code.to_i) + cache[url] = body end end - response + body end end ## # The working Cache object.