From: Christopher Schmidt Date: Sun, 11 May 2008 20:03:17 +0000 (+0000) Subject: Add support for accessing changesets as XML through the API via the X-Git-Tag: live~8121^2~356 X-Git-Url: https://git.openstreetmap.org./rails.git/commitdiff_plain/e48cbc6a5f54a0e18dc581ccbac3b13284313125 Add support for accessing changesets as XML through the API via the changeset controller "read" method --- diff --git a/app/controllers/changeset_controller.rb b/app/controllers/changeset_controller.rb index f91ae09bf..3e88eeec3 100644 --- a/app/controllers/changeset_controller.rb +++ b/app/controllers/changeset_controller.rb @@ -45,6 +45,15 @@ class ChangesetController < ApplicationController map { |memb| [memb[0], ids[memb[0]][memb[1].to_i] || memb[1], memb[2]] } return r end + + def read + begin + changeset = Changeset.find(params[:id]) + render :text => changeset.to_xml.to_s, :content_type => "text/xml" + rescue ActiveRecord::RecordNotFound + render :nothing => true, :status => :not_found + end + end def upload if not request.put? diff --git a/app/models/changeset.rb b/app/models/changeset.rb index 85621dce2..983f7544c 100644 --- a/app/models/changeset.rb +++ b/app/models/changeset.rb @@ -70,4 +70,37 @@ class Changeset < ActiveRecord::Base end end end + + def to_xml + doc = OSM::API.new.get_xml_doc + doc.root << to_xml_node() + return doc + end + def to_xml_node(user_display_name_cache = nil) + el1 = XML::Node.new 'changeset' + el1['id'] = self.id.to_s + + user_display_name_cache = {} if user_display_name_cache.nil? + + if user_display_name_cache and user_display_name_cache.key?(self.user_id) + # use the cache if available + elsif self.user.data_public? + user_display_name_cache[self.user_id] = self.user.display_name + else + user_display_name_cache[self.user_id] = nil + end + + el1['user'] = user_display_name_cache[self.user_id] unless user_display_name_cache[self.user_id].nil? + + self.tags.each do |k,v| + el2 = XML::Node.new('tag') + el2['k'] = k.to_s + el2['v'] = v.to_s + el1 << el2 + end + + el1['created_at'] = self.created_at.xmlschema + + return el1 + end end diff --git a/config/routes.rb b/config/routes.rb index 64293b34d..9196fae1b 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -2,6 +2,7 @@ ActionController::Routing::Routes.draw do |map| # API map.connect "api/#{API_VERSION}/changeset/create", :controller => 'changeset', :action => 'create' + map.connect "api/#{API_VERSION}/changeset/:id", :controller => 'changeset', :action => 'read' map.connect "api/#{API_VERSION}/changeset/upload", :controller => 'changeset', :action => 'upload' map.connect "api/#{API_VERSION}/node/create", :controller => 'node', :action => 'create'