Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

fixed get method parameters

  • Loading branch information...
commit 95b9c420aa67e56519722d8f5156f40a61ccefcc 1 parent 367ab48
Fatih Erikli fatiherikli authored
1  apiplayground/__init__.py
View
@@ -0,0 +1 @@
+from playground import APIPlayground
10 apiplayground/browser.py → apiplayground/playground.py
View
@@ -6,10 +6,10 @@
from django.template import RequestContext
from apiplayground.forms import FeedbackForm
-from apiplayground.settings import API_BROWSER_SCHEMA_PATH
+from apiplayground.settings import API_PLAYGROUND_SCHEMA_PATH
-class APIBrowser(object):
+class APIPlayground(object):
"""
A base class that encapsulates all api browser options.
"""
@@ -44,7 +44,7 @@ def load_schema(self):
"""
Loads the schema from file with defined deserialization module.
"""
- return self.get_serializer().load(API_BROWSER_SCHEMA_PATH)
+ return self.get_serializer().load(API_PLAYGROUND_SCHEMA_PATH)
def browser_index(self, request):
"""
@@ -95,8 +95,8 @@ def get_urls(self):
You can override method for adding extra views.
"""
return [
- url("^$", self.browser_index, name="api_browser_index"),
- url("^submit-feedback$", self.submit_feedback, name="api_browser_submit_feedback"),
+ url("^$", self.browser_index, name="api_playground_index"),
+ url("^submit-feedback$", self.submit_feedback, name="api_playground_submit_feedback"),
]
@property
4 apiplayground/settings.py
View
@@ -1,4 +1,4 @@
from django.conf import settings
-API_BROWSER_SCHEMA_PATH = getattr(settings,
- "API_BROWSER_SCHEMA_PATH", "api_browser_schema.json")
+API_PLAYGROUND_SCHEMA_PATH = getattr(settings,
+ "API_PLAYGROUND_SCHEMA_PATH", "api_playground_schema.json")
4 apiplayground/static/api_browser/js/jquery.form2json.js
View
@@ -24,6 +24,10 @@
result_object[input_name] = get_input_value($(this));
});
+// if ($.isEmptyObject(result_object)) {
+// return ""
+// }
+
return result_object;
};
18 apiplayground/static/api_browser/js/jquery.rest-form.js
View
@@ -7,6 +7,11 @@
* */
!(function ($) {
+ var GET = "GET",
+ POST = "POST",
+ PUT = "PUT",
+ DELETE = "DELETE";
+
$.fn.restForm = function (_options) {
var options = $.extend({
"submit": function () {},
@@ -36,15 +41,22 @@
options.submit.call(this, form, build_request_headers(method, url, data,
content_type));
- // calling api resource
- $.ajax({
+ var ajax_parameters = {
url: url,
type: method,
data: JSON.stringify(data),
contentType: content_type,
dataType: 'json',
processData: false
- }).complete(options.complete.bind(this, form));
+ };
+
+ if (method === GET) {
+ ajax_parameters.processData = true;
+ ajax_parameters.data = data;
+ }
+
+ // calling api resource
+ $.ajax(ajax_parameters).complete(options.complete.bind(this, form));
return false;
2  apiplayground/templates/api_browser/base.html
View
@@ -8,7 +8,7 @@
<body>
<header>
- <h1><a href="/">API Browser</a></h1>
+ <h1><a href="#">{{ schema.title }}</a></h1>
</header>
{% block content %}
{% endblock %}
4 apiplayground/templates/api_browser/index.html
View
@@ -7,7 +7,7 @@
<section class="resource">
<header>
<h3>{{ resource.name }}</h3>
- <p>Helps you for managing todos.</p>
+ <p>{{ resource.description }}</p>
</header>
<ul>
{% for endpoint in resource.endpoints %}
@@ -51,7 +51,7 @@
{% block footer %}
<!-- submit feedback form -->
<div id="submit-feedback">
- <form action="{% url api_browser_submit_feedback %}" method="post">
+ <form action="{% url api_playground_submit_feedback %}" method="post">
{% csrf_token %}
{{ feedback_form.as_p }}
<input type="submit" value="Submit">
6 example/api/views.py → example/api/playgrounds.py
View
@@ -1,9 +1,9 @@
-from apiplayground.browser import APIBrowser
+from apiplayground import APIPlayground
-class ExampleAPIBrowser(APIBrowser):
+class ExampleAPIPlayground(APIPlayground):
schema = {
- "title": "API Browser",
+ "title": "API Playground",
"base_url": "http://localhost/api/",
"resources": [
{
8 example/api/urls.py
View
@@ -1,16 +1,14 @@
from django.conf.urls.defaults import *
-from api.views import ExampleAPIBrowser
-
-from links.resources import LinksResource
from todos.resources import ToDoResource
+from links.resources import LinksResource
+from api.playgrounds import ExampleAPIPlayground
urlpatterns = patterns('',
(r'^', include(ToDoResource().urls)),
(r'^', include(LinksResource().urls)),
- (r'browser/', include(ExampleAPIBrowser().urls)),
-
+ (r'browser/', include(ExampleAPIPlayground().urls)),
)
Please sign in to comment.
Something went wrong with that request. Please try again.