diff --git a/app/__init__.py b/app/__init__.py index 7e34c6c64..e5216b4ad 100644 --- a/app/__init__.py +++ b/app/__init__.py @@ -9,6 +9,9 @@ from flask.ext.sqlalchemy import SQLAlchemy from flask_login import LoginManager from flask_wtf import CsrfProtect from werkzeug.exceptions import abort +from pygments import highlight +from pygments.lexers import JavascriptLexer +from pygments.formatters import HtmlFormatter from app.notify_client.api_client import NotificationsAdminAPIClient from app.notify_client.api_key_api_client import ApiKeyApiClient from app.notify_client.user_api_client import UserApiClient @@ -61,6 +64,7 @@ def create_app(config_name, config_overrides=None): application.add_template_filter(replace_placeholders) application.add_template_filter(nl2br) application.add_template_filter(format_datetime) + application.add_template_filter(syntax_highlight_json) application.after_request(useful_headers_after_request) register_errorhandlers(application) @@ -144,6 +148,10 @@ def replace_placeholders(template, values): )) +def syntax_highlight_json(code): + return Markup(highlight(code, JavascriptLexer(), HtmlFormatter(noclasses=True))) + + def format_datetime(date): date = dateutil.parser.parse(date) native = date.replace(tzinfo=None) diff --git a/app/assets/stylesheets/app.scss b/app/assets/stylesheets/app.scss index 19c15a659..dcb2a9f2b 100644 --- a/app/assets/stylesheets/app.scss +++ b/app/assets/stylesheets/app.scss @@ -57,3 +57,8 @@ a { } } + +.highlight { + font-family: monospace; + overflow-x: scroll; +} diff --git a/app/templates/views/documentation.html b/app/templates/views/documentation.html index 4d9c5a648..bc9723c39 100644 --- a/app/templates/views/documentation.html +++ b/app/templates/views/documentation.html @@ -13,7 +13,7 @@
Notify standard claims:
-- typ: JWT - alg: HS256 -+ {{''' +{ + "typ": "JWT", + "alg": "HS256" +} + '''|syntax_highlight_json}}
Notify application specific:
-- iss: service id - iat: creation time in epoch seconds (UTC) - req: signed request - pay: signed payload (POST requests only) -- + {{""" +{ + iss: 'string', // service id + iat: 0, // creation time in epoch seconds (UTC) + req: 'string', // signed request + pay: 'string', // signed payload (POST requests only) +} + """|syntax_highlight_json}} +
Notify API tokens sign both the request being made, and for POST requests, the payload.
@@ -56,7 +62,7 @@
Request signing is of the form HTTP METHOD PATH.
-GET /notification/1234
+ {{ "GET /notification/1234"|syntax_highlight_json }}
@@ -68,64 +74,68 @@
To create a text notification
+POST /notifications/sms
-
+ {{
+ """
+{
+ 'to': '+441234123123',
+ 'template': 1
+}
+ """|syntax_highlight_json
+ }}
+-
- {
- 'to': '+441234123123',
- 'template': 1
- }
-
- Where 'to' is the phone number and 'template' is the template id to send.
+ Where ‘to’ is the phone number and ‘template’ is the template ID to send.
- Response: -
- {
- 'notification':
- {
- 'to': '+441234123123',
- 'createdAt': '2016-01-01T09:00:00.999999Z',
- 'status': 'created',
- 'id': 1,
- 'message': '....',
- 'method': 'sms',
- 'jobId': 1
- }
- }
-
+ Response:
+ To get the status of a text notification
-
-
- GET /notifications/{id}
-
-
-
- {
- 'notification':
- {
- 'status': 'sent',
- 'createdAt': '2016-01-01T09:00:00.999999Z',
- 'to': '+447827992607',
- 'method': 'sms',
- 'sentAt': '2016-01-01T09:01:00.999999Z',
- 'id': 1,
- 'message': '...',
- 'jobId': 1,
- 'sender': 'sms-partner'
- }
- }
-
-
+ {{"""
+{
+ 'notification':
+ {
+ 'status': 'sent',
+ 'createdAt': '2016-01-01T09:00:00.999999Z',
+ 'to': '+447827992607',
+ 'method': 'sms',
+ 'sentAt': '2016-01-01T09:01:00.999999Z',
+ 'id': 1,
+ 'message': '...',
+ 'jobId': 1,
+ 'sender': 'sms-partner'
+ }
+}
+ """|syntax_highlight_json }}
+