mirror of https://github.com/zulip/zulip.git
Add support for subdomain URIs to /api and /api/endpoints.
To the extent possible, we share code with the already-existing IntegrationView code path.
This commit is contained in:
parent
bc827b2a6f
commit
de11e7c1b3
|
@ -46,7 +46,7 @@ to pull out the resulting HTML :)
|
|||
#}
|
||||
|
||||
<h4>Stream message</h4>
|
||||
<div class="codehilite"><pre>curl {{ external_api_uri }}/v1/messages <span class="se">\</span>
|
||||
<div class="codehilite"><pre>curl {{ external_api_uri_subdomain }}/v1/messages <span class="se">\</span>
|
||||
-u BOT_EMAIL_ADDRESS:BOT_API_KEY <span class="se">\</span>
|
||||
-d <span class="s2">"type=stream"</span> <span class="se">\</span>
|
||||
-d <span class="s2">"to=Denmark"</span> <span class="se">\</span>
|
||||
|
@ -55,7 +55,7 @@ to pull out the resulting HTML :)
|
|||
</div>
|
||||
|
||||
<h4>Private message</h4>
|
||||
<div class="codehilite"><pre>curl {{ external_api_uri }}/v1/messages <span class="se">\</span>
|
||||
<div class="codehilite"><pre>curl {{ external_api_uri_subdomain }}/v1/messages <span class="se">\</span>
|
||||
-u BOT_EMAIL_ADDRESS:BOT_API_KEY <span class="se">\</span>
|
||||
-d <span class="s2">"type=private"</span> <span class="se">\</span>
|
||||
-d <span class="s2">"to=hamlet@example.com"</span> <span class="se">\</span>
|
||||
|
@ -106,19 +106,19 @@ to pull out the resulting HTML :)
|
|||
<h4>Stream message</h4>
|
||||
<div class="codehilite"><pre>zulip-send --stream Denmark --subject Castle \
|
||||
--user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5{% if api_site_required %} \
|
||||
--site={{ external_api_uri }}{% endif %}</pre></div>
|
||||
--site={{ external_api_uri_subdomain }}{% endif %}</pre></div>
|
||||
|
||||
<h4>Private message</h4>
|
||||
<div class="codehilite"><pre>zulip-send hamlet@example.com \
|
||||
--user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5{% if api_site_required %} \
|
||||
--site={{ external_api_uri }}{% endif %}</pre></div>
|
||||
--site={{ external_api_uri_subdomain }}{% endif %}</pre></div>
|
||||
|
||||
<h4>Passing in the message on the command-line</h4>
|
||||
<p>If you'd like, you can also provide the message on the command-line with the <code>-m</code> flag, as follows:</p>
|
||||
<div class="codehilite"><pre>zulip-send --stream Denmark --subject Castle \
|
||||
-m <span class="s2">"Something is rotten in the state of Denmark."</span> \
|
||||
--user othello-bot@example.com --api-key a0b1c2d3e4f5a6b7c8d9e0f1a2b3c4d5{% if api_site_required %} \
|
||||
--site={{ external_api_uri }}{% endif %}
|
||||
--site={{ external_api_uri_subdomain }}{% endif %}
|
||||
</pre></div>
|
||||
|
||||
<p>You can omit the <code>user</code>{% if api_site_required %}, <code>api-key</code>, and
|
||||
|
@ -149,8 +149,6 @@ to pull out the resulting HTML :)
|
|||
<div class="codehilite"><pre><span class="k">[api]</span>
|
||||
<span class="na">key</span><span class="o">=</span><span class="s">BOT_API_KEY</span>
|
||||
<span class="na">email</span><span class="o">=</span><span class="s">BOT_EMAIL_ADDRESS</span>
|
||||
{% if api_site_required %}<span class="na">site</span><span class="o">=</span><span class="s">{{ external_api_uri }}</span>{% endif %}</pre></div>
|
||||
{% if api_site_required %}<span class="na">site</span><span class="o">=</span><span class="s">{{ external_api_uri_subdomain }}</span>{% endif %}</pre></div>
|
||||
</div>
|
||||
{% endblock %}
|
||||
|
||||
|
||||
|
|
|
@ -269,7 +269,6 @@ def accounts_accept_terms(request):
|
|||
'special_message_template' : special_message_template },
|
||||
request=request)
|
||||
|
||||
|
||||
@authenticated_json_post_view
|
||||
@has_request_variables
|
||||
def json_invite_users(request, user_profile, invitee_emails_raw=REQ("invitee_emails")):
|
||||
|
|
|
@ -26,6 +26,11 @@ class ApiURLView(TemplateView):
|
|||
add_api_uri_context(context, self.request)
|
||||
return context
|
||||
|
||||
|
||||
class APIView(ApiURLView):
|
||||
template_name = 'zerver/api.html'
|
||||
|
||||
|
||||
class IntegrationView(ApiURLView):
|
||||
template_name = 'zerver/integrations.html'
|
||||
|
||||
|
@ -46,13 +51,17 @@ class IntegrationView(ApiURLView):
|
|||
|
||||
def api_endpoint_docs(request):
|
||||
# type: (HttpRequest) -> HttpResponse
|
||||
context = {} # type: Dict[str, Any]
|
||||
add_api_uri_context(context, request)
|
||||
|
||||
raw_calls = open('templates/zerver/api_content.json', 'r').read()
|
||||
calls = ujson.loads(raw_calls)
|
||||
langs = set()
|
||||
for call in calls:
|
||||
call["endpoint"] = "%s/v1/%s" % (settings.EXTERNAL_API_URI, call["endpoint"])
|
||||
call["endpoint"] = "%s/v1/%s" % (context["external_api_uri_subdomain"],
|
||||
call["endpoint"])
|
||||
call["example_request"]["curl"] = call["example_request"]["curl"].replace("https://api.zulip.com",
|
||||
settings.EXTERNAL_API_URI)
|
||||
context["external_api_uri_subdomain"])
|
||||
response = call['example_response']
|
||||
if '\n' not in response:
|
||||
# For 1-line responses, pretty-print them
|
||||
|
|
|
@ -7,7 +7,7 @@ import os.path
|
|||
import zerver.forms
|
||||
from zproject import dev_urls
|
||||
from zproject.legacy_urls import legacy_urls
|
||||
from zerver.views.integrations import IntegrationView
|
||||
from zerver.views.integrations import IntegrationView, APIView
|
||||
from zerver.lib.integrations import WEBHOOK_INTEGRATIONS
|
||||
|
||||
# NB: There are several other pieces of code which route requests by URL:
|
||||
|
@ -93,7 +93,7 @@ i18n_urls = [
|
|||
url(r'^register/(?P<domain>\S+)/$', 'zerver.views.accounts_home_with_domain'),
|
||||
|
||||
# API and integrations documentation
|
||||
url(r'^api/$', TemplateView.as_view(template_name='zerver/api.html')),
|
||||
url(r'^api/$', APIView.as_view(template_name='zerver/api.html')),
|
||||
url(r'^api/endpoints/$', 'zerver.views.integrations.api_endpoint_docs'),
|
||||
url(r'^integrations/$', IntegrationView.as_view()),
|
||||
url(r'^about/$', TemplateView.as_view(template_name='zerver/about.html')),
|
||||
|
|
Loading…
Reference in New Issue