]> git.openstreetmap.org Git - rails.git/blobdiff - app/controllers/api/ways_controller.rb
API JSON output
[rails.git] / app / controllers / api / ways_controller.rb
index b8ce1010f29cc1e3fa046c67b78a1733882892c8..a721f82f7ade94e92d51a76a2586cc64a9a96197 100644 (file)
@@ -11,6 +11,13 @@ module Api
     before_action :check_api_readable, :except => [:create, :update, :delete]
     around_action :api_call_handle_error, :api_call_timeout
 
+    before_action :default_format_xml
+
+    # Set format to xml unless client requires a specific format
+    def default_format_xml
+      request.format = "xml" unless params[:format]
+    end
+
     def create
       assert_method :put
 
@@ -22,16 +29,15 @@ module Api
     end
 
     def show
-      way = Way.find(params[:id])
-
-      response.last_modified = way.timestamp
+      @way = Way.find(params[:id])
 
-      if way.visible
-        @ways = [way]
+      response.last_modified = @way.timestamp
 
+      if @way.visible
         # Render the result
         respond_to do |format|
           format.xml
+          format.json
         end
       else
         head :gone
@@ -64,27 +70,24 @@ module Api
     end
 
     def full
-      way = Way.includes(:nodes => :node_tags).find(params[:id])
+      @way = Way.includes(:nodes => :node_tags).find(params[:id])
 
-      if way.visible
+      if @way.visible
         visible_nodes = {}
-        # changeset_cache = {}
-        # user_display_name_cache = {}
 
         @nodes = []
 
-        way.nodes.uniq.each do |node|
+        @way.nodes.uniq.each do |node|
           if node.visible
             @nodes << node
             visible_nodes[node.id] = node
           end
         end
 
-        @ways = [way]
-
         # Render the result
         respond_to do |format|
           format.xml
+          format.json
         end
       else
         head :gone
@@ -105,6 +108,7 @@ module Api
       # Render the result
       respond_to do |format|
         format.xml
+        format.json
       end
     end
 
@@ -120,6 +124,7 @@ module Api
       # Render the result
       respond_to do |format|
         format.xml
+        format.json
       end
     end
   end