Make REST API urls available under /json/

Now we can begin the transition of the app to the same interface that our
API clients use.

(imported from commit 5b5001237722692f27f5de687f01d97fa0b87ed0)
This commit is contained in:
Luke Faraone 2013-07-05 14:04:47 -04:00
parent b6cfb40140
commit ddf0189307
1 changed files with 43 additions and 33 deletions

View File

@ -1,5 +1,5 @@
from django.conf import settings
from django.conf.urls import patterns, url
from django.conf.urls import patterns, url, include
from django.views.generic import TemplateView, RedirectView
import os.path
import zephyr.forms
@ -130,44 +130,47 @@ urlpatterns += patterns('zephyr.views',
# This json format view used by the API accepts a username password/pair and returns an API key.
url(r'^api/v1/fetch_api_key$', 'api_fetch_api_key'),
# JSON format views used by the redesigned API, accept basic auth username:password.
# GET returns messages, possibly filtered, POST sends a message
url(r'^api/v1/messages$', 'rest_dispatch',
{'GET': 'get_old_messages_backend',
'PATCH': 'update_message_backend',
'POST': 'send_message_backend'}),
url(r'^api/v1/streams$', 'rest_dispatch',
{'GET': 'get_public_streams_backend'}),
# GET returns "stream info" (undefined currently?), HEAD returns whether stream exists (200 or 404)
url(r'^api/v1/streams/(?P<stream_name>.*)/members$', 'rest_dispatch',
{'GET': 'get_subscribers_backend'}),
url(r'^api/v1/streams/(?P<stream_name>.*)$', 'rest_dispatch',
{'HEAD': 'stream_exists_backend',
'GET': 'stream_exists_backend'}),
url(r'^api/v1/users$', 'rest_dispatch',
{'GET': 'get_members_backend'}),
url(r'^api/v1/users/me$', 'rest_dispatch',
{'GET': 'get_profile_backend'}),
url(r'^api/v1/users/me/enter-sends$', 'rest_dispatch',
{'POST': 'json_change_enter_sends'}),
url(r'^api/v1/users/me/pointer$', 'rest_dispatch',
{'GET': 'get_pointer_backend',
'PUT': 'update_pointer_backend'}),
# GET lists your streams, POST bulk adds, PATCH bulk modifies/removes
url(r'^api/v1/users/me/subscriptions$', 'rest_dispatch',
{'GET': 'list_subscriptions_backend',
'POST': 'add_subscriptions_backend',
'PATCH': 'update_subscriptions_backend'}),
url(r'^api/v1/register$', 'rest_dispatch',
{'POST': 'api_events_register'}),
# These are integration-specific web hook callbacks
url(r'^api/v1/external/beanstalk$', 'api_beanstalk_webhook'),
url(r'^api/v1/external/beanstalk$' , 'api_beanstalk_webhook'),
url(r'^api/v1/external/github$', 'api_github_landing'),
url(r'^api/v1/external/jira$', 'api_jira_webhook'),
url(r'^api/v1/external/pivotal$', 'api_pivotal_webhook'),
)
v1_api_and_json_patterns = patterns('zephyr.views',
# JSON format views used by the redesigned API, accept basic auth username:password.
# GET returns messages, possibly filtered, POST sends a message
url(r'^messages$', 'rest_dispatch',
{'GET': 'get_old_messages_backend',
'PATCH': 'update_message_backend',
'POST': 'send_message_backend'}),
url(r'^streams$', 'rest_dispatch',
{'GET': 'get_public_streams_backend'}),
# GET returns "stream info" (undefined currently?), HEAD returns whether stream exists (200 or 404)
url(r'^streams/(?P<stream_name>.*)/members$', 'rest_dispatch',
{'GET': 'get_subscribers_backend'}),
url(r'^streams/(?P<stream_name>.*)$', 'rest_dispatch',
{'HEAD': 'stream_exists_backend',
'GET': 'stream_exists_backend'}),
url(r'^users$', 'rest_dispatch',
{'GET': 'get_members_backend'}),
url(r'^users/me$', 'rest_dispatch',
{'GET': 'get_profile_backend'}),
url(r'^users/me/enter-sends$', 'rest_dispatch',
{'POST': 'json_change_enter_sends'}),
url(r'^users/me/pointer$', 'rest_dispatch',
{'GET': 'get_pointer_backend',
'PUT': 'update_pointer_backend'}),
# GET lists your streams, POST bulk adds, PATCH bulk modifies/removes
url(r'^users/me/subscriptions$', 'rest_dispatch',
{'GET': 'list_subscriptions_backend',
'POST': 'add_subscriptions_backend',
'PATCH': 'update_subscriptions_backend'}),
url(r'^register$', 'rest_dispatch',
{'POST': 'api_events_register'}),
)
urlpatterns += patterns('zephyr.tornadoviews',
# Tornado views
url(r'^api/v1/get_messages$', 'api_get_messages'),
@ -179,6 +182,13 @@ urlpatterns += patterns('zephyr.tornadoviews',
url(r'^notify_tornado$', 'notify'),
)
# Include the dual-use patterns twice
urlpatterns += patterns('',
url(r'^api/v1/', include(v1_api_and_json_patterns)),
url(r'^json/', include(v1_api_and_json_patterns)),
)
if not settings.DEPLOYED:
use_prod_static = getattr(settings, 'PIPELINE', False)
static_root = os.path.join(settings.DEPLOY_ROOT,