4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
|
# File 'lib/geoplanet/base.rb', line 4
def build_url(resource_path, options = {})
check_options_for(resource_path, options)
filters = (options)
matrix_params = (options)
query_params = (options)
query_params[:appid] ||= GeoPlanet.appid
raise ArgumentError, "appid or q filter missing" if query_params[:appid].nil? || resource_path == 'places' && filters[:q].nil?
q = ".q('#{filters[:q]}')" if filters[:q]
type = ".type('#{filters[:type]}')" if filters[:type]
query_string = q && type ? "$and(#{q},#{type})" : "#{q}#{type}"
matrix_params = matrix_params.any? ? ";#{matrix_params.map{|k,v| "#{k}=#{v}"}.join(';')}" : nil
query_params = query_params.any? ? "?#{query_params.map{|k,v| "#{k}=#{v}"}.join('&')}" : nil
query_string += "#{matrix_params}#{query_params}"
"#{GeoPlanet::API_URL}#{resource_path}#{query_string}"
end
|