Commits

takanao ENDOH committed 9db9b3a

Refactored API.

  • Participants
  • Parent commits c2938a2

Comments (0)

Files changed (1)

monologista/api/views.py

         mimetype='text/plain; charset=utf-8', status=404)
 
 # Test Implementations.
+def api_response(data, format):
+    return HttpResponse(
+        dump(data, format),
+        mimetype='application/%s' % format)
+
 @allow_methods('GET')
 def apis(request, format):
     result = dict()
         regex_pattern = i.__str__().split()[-1][:-1]
         result[i.name] = (
             "/api/%s" % reverse_helper(
-                re.compile(regex_pattern.replace(r"\.", ".").replace("(json|xml)",r"\w+")),
+                re.compile(regex_pattern.replace(r"\.", ".").replace("(json|xml)", r"\w+")),
                 format="json", username="spam", monology_id="0"),
             regex_pattern,
             tuple(set(i.callback.func_closure[0].cell_contents)
                 & set(['GET', 'POST', 'PUT', 'DELETE'])),
         )
+    return api_response(result, format)
 
-    _buffer = StringIO()
-    dict(
-        json = lambda x: simplejson.dump(x, _buffer),
-        # TODO delete メッセージXMLシリアライザの作成
-        xml = None,
-    )[format](result)
-    return HttpResponse(_buffer.getvalue(), mimetype='application/%s' % format)
-