Explorar el Código

Added possibility to post data to /dataelements.json

Manuel Gall hace 3 años
padre
commit
75215483c7
Se han modificado 2 ficheros con 27 adiciones y 0 borrados
  1. 26 0
      frames
  2. 1 0
      frames.xml

+ 26 - 0
frames

@@ -225,6 +225,31 @@ class GetFrames < Riddl::Implementation #{{{
 end #}}}
 
 
+class SetDataElements < Riddl::Implementation #{{{
+  def response    
+    savejson = @p.map { |o| Hash[o.name, o.value] }.to_json
+    path = File.join('data',@r[0],'dataelements.json')
+    File.write(path, savejson)
+    
+    #puts xyz
+    
+    #puts JSON.pretty_generate(@p.to_json)
+    
+    
+    
+    #puts @p.length()
+    #puts @p[0].name
+    #puts @p[0].value
+    
+    #fname = File.join('data',@r[-2],'dataelements.json')
+    #if File.exists? fname
+    #  Riddl::Parameter::Complex.new('value','application/json',File.read(fname))
+    #else
+    #  @status = 404
+    #end
+  end
+end #}}}
+
 class GetDataElements < Riddl::Implementation #{{{
   def response
     fname = File.join('data',@r[-2],'dataelements.json')
@@ -482,6 +507,7 @@ server = Riddl::Server.new(File.join(__dir__,'/frames.xml'), :host => 'localhost
       end
       
       on resource 'dataelements.json' do
+        run SetDataElements if post
         run GetDataElements if get
       end
       

+ 1 - 0
frames.xml

@@ -99,6 +99,7 @@
       </resource>
       <resource relative="dataelements.json">
         <get out="json"/>
+        <post />
       </resource>