Skip to content

Commit

Permalink
DRY up escaping content
Browse files Browse the repository at this point in the history
  • Loading branch information
saturnflyer committed Nov 18, 2011
1 parent 84e46d9 commit 89f1043
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions lib/simple_geo/client.rb
Expand Up @@ -132,7 +132,7 @@ def get_context(lat, lon, filter=nil)
end

def get_context_by_address(address, filter=nil)
address = URI.escape(address, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
address = escape_for_url(address)
geojson_hash = get Endpoint.context_by_address(address, filter)
HashUtils.recursively_symbolize_keys geojson_hash
end
Expand Down Expand Up @@ -168,7 +168,7 @@ def get_places(lat, lon, options={})
end

def get_places_by_address(address, options={})
address = URI.escape(address, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
address = escape_for_url(address)
options[:category] = category_query_string(options[:category]) unless options[:category].nil?
geojson_hash = get Endpoint.places_by_address(address, options)
HashUtils.recursively_symbolize_keys geojson_hash
Expand Down Expand Up @@ -203,7 +203,11 @@ def put(endpoint, data=nil)
private

def category_query_string(list)
Array(list).map{|cat| URI.escape(cat, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]")) }.join('&category=')
Array(list).map{|cat| escape_for_url(cat) }.join('&category=')
end

def escape_for_url(value)
URI.escape(value, Regexp.new("[^#{URI::PATTERN::UNRESERVED}]"))
end
end

Expand Down

0 comments on commit 89f1043

Please sign in to comment.