module RGeoServer::GeoServerUrlHelpers
Constants
- URI_FORMATS
Valid formats for REST API See docs.geoserver.org/stable/en/user/rest/api/details.html
- URI_REGEX
Regexp processing for #URI_SEQUENCES
- URI_SEQUENCES
Valid URI sequences for REST API See docs.geoserver.org/stable/en/user/rest/index.html
Public Instance Methods
url_for(base, options = {})
click to toggle source
See docs.geoserver.org/latest/en/user/rest/api/ @param [Hash] base, examples:
-
{ :workspaces => nil }
@param [Hash] options @return [String] baseURL for REST API, e.g.,:
-
settings.xml
-
layers/name.xml
-
styles/name.xml
-
workspaces/name.xml
-
workspaces/name/settings.xml
-
namespaces/name.xml
-
workspaces/name/datastores/name.xml
-
workspaces/name/datastores/name/featuretype/name.xml
# File lib/rgeoserver/geoserver_url_helpers.rb, line 60 def url_for base, options = {} raise GeoServerArgumentError, "options must be Hash" unless options.is_a? Hash if base.is_a? String $stderr.puts "WARNING: deprecated usage -- base should be Hash" base = { base.to_sym => nil } if base.is_a? String end base = Hash[base.map {|k,v| [k.to_sym, v]}] unless base.keys.select {|k| not k.is_a? Symbol}.size == 0 format = (options.delete(:format) if options.include?(:format)) || :xml raise GeoServerArgumentError, "Unknown REST API format: '#{format}'" unless URI_FORMATS.include?(format) new_base = base.collect {|k,v| v.nil?? "#{k}" : "#{k}/#{v}"}.join('/').to_s new_base = new_base.gsub(%r{/$}, '') raise GeoServerArgumentError, "Invalid REST URI syntax: #{new_base} from #{base}" unless URI_REGEX.each.select {|r| r.match(new_base)}.size > 0 new_base += ".#{format}" if not options.empty? new_base += "?" + options.collect {|k,v| [CGI::escape(k.to_s), CGI::escape(v.to_s)].join('=')}.join('&') end ap "url_for: #{base} #{options} => #{new_base}" if $DEBUG new_base end