From 3790f3e83beacf391e1e2fd3a090e9a67b27357e Mon Sep 17 00:00:00 2001 From: dibyaaaaax Date: Mon, 23 Dec 2019 15:10:10 +0545 Subject: [PATCH 1/4] Add python examples for API v3 Documentation --- docs/api/v3.rst | 453 +++++++++++++++++++++++++++++++++++++++--------- docs/conf.py | 1 + 2 files changed, 370 insertions(+), 84 deletions(-) diff --git a/docs/api/v3.rst b/docs/api/v3.rst index 63c0b385dfc..3620d9275a3 100644 --- a/docs/api/v3.rst +++ b/docs/api/v3.rst @@ -80,9 +80,20 @@ Projects list **Example request**: - .. sourcecode:: bash + .. tabs:: - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/ + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/ + + .. code-tab:: python + + import requests + URL = 'https://readthedocs.org/api/v3/projects/' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response**: @@ -108,9 +119,20 @@ Project details **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/ - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/ + .. code-tab:: python + + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response**: @@ -184,13 +206,27 @@ Project create **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl \ + -X POST \ + -H "Authorization: Token " https://readthedocs.org/api/v3/projects/ \ + -H "Content-Type: application/json" \ + -d @body.json + + .. code-tab:: python - $ curl \ - -X POST \ - -H "Authorization: Token " https://readthedocs.org/api/v3/projects/ \ - -H "Content-Type: application/json" \ - -d @body.json + import requests + import json + URL = 'https://readthedocs.org/api/v3/projects/' + TOKEN = '' + HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + data = json.load(open('body.json', 'rb')) + response = requests.post(URL, + json = data, headers = HEADERS) + print(response.text) The content of ``body.json`` is like, @@ -220,13 +256,27 @@ Project update **Example request**: - .. sourcecode:: bash + .. tabs:: - $ curl \ - -X PATCH \ - -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/ \ - -H "Content-Type: application/json" \ - -d @body.json + .. code-tab:: bash + + $ curl \ + -X PATCH \ + -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/ \ + -H "Content-Type: application/json" \ + -d @body.json + + .. code-tab:: python + + import requests + import json + URL = 'https://readthedocs.org/api/v3/projects/pip/' + TOKEN = '' + HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + data = json.load(open('body.json', 'rb')) + response = requests.patch(URL, + json = data, headers = HEADERS) + print(response.text) The content of ``body.json`` is like, @@ -272,9 +322,20 @@ Versions listing **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/versions/ - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/versions/ + .. code-tab:: python + + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/versions/' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response**: @@ -300,9 +361,20 @@ Version detail **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/versions/stable/ + + .. code-tab:: python - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/versions/stable/ + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/versions/stable/' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response**: @@ -352,13 +424,27 @@ Version update **Example request**: - .. sourcecode:: bash + .. tabs:: - $ curl \ - -X PATCH \ - -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/version/0.23/ \ - -H "Content-Type: application/json" \ - -d @body.json + .. code-tab:: bash + + $ curl \ + -X PATCH \ + -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/version/0.23/ \ + -H "Content-Type: application/json" \ + -d @body.json + + .. code-tab:: python + + import requests + import json + URL = 'https://readthedocs.org/api/v3/projects/pip/ersion/0.23/' + TOKEN = '' + HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + data = json.load(open('body.json', 'rb')) + response = requests.patch(URL, + json = data, headers = HEADERS) + print(response.text) The content of ``body.json`` is like, @@ -393,9 +479,20 @@ Build details **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/builds/8592686/?expand=config - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/builds/8592686/?expand=config + .. code-tab:: python + + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/builds/8592686/?expand=config' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response**: @@ -477,9 +574,20 @@ Builds listing **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/builds/ + + .. code-tab:: python - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/builds/ + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/builds/' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response**: @@ -506,11 +614,22 @@ Build triggering **Example request**: - .. sourcecode:: bash + .. tabs:: - $ curl \ - -X POST \ - -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/versions/latest/builds/ + .. code-tab:: bash + + $ curl \ + -X POST \ + -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/versions/latest/builds/ + + .. code-tab:: python + + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/versions/latest/builds/' + TOKEN = '' + HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + response = requests.post(URL, headers = HEADERS) + print(response.text) **Example response**: @@ -545,9 +664,20 @@ Subproject details **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/subprojects/subproject-alias/ - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/subprojects/subproject-alias/ + .. code-tab:: python + + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/subprojects/subproject-alias/' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response**: @@ -572,9 +702,20 @@ Subprojects listing **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/subprojects/ + + .. code-tab:: python - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/subprojects/ + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/subprojects/' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response**: @@ -598,13 +739,27 @@ Subproject create **Example request**: - .. sourcecode:: bash + .. tabs:: - $ curl \ - -X POST \ - -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/subprojects/ \ - -H "Content-Type: application/json" \ - -d @body.json + .. code-tab:: bash + + $ curl \ + -X POST \ + -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/subprojects/ \ + -H "Content-Type: application/json" \ + -d @body.json + + .. code-tab:: python + + import requests + import json + URL = 'https://readthedocs.org/api/v3/projects/pip/subprojects/' + TOKEN = '' + HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + data = json.load(open('body.json', 'rb')) + response = requests.post(URL, + json = data, headers = HEADERS) + print(response.text) The content of ``body.json`` is like, @@ -635,11 +790,22 @@ Subproject delete **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl \ + -X DELETE \ + -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/subprojects/subproject-alias/ - $ curl \ - -X DELETE \ - -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/subprojects/subproject-alias/ + .. code-tab:: python + + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/subprojects/subproject-alias/' + TOKEN = '' + HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + response = requests.delete(URL, headers = HEADERS) + print(response.text) :statuscode 204: Subproject deleted successfully @@ -660,9 +826,20 @@ Translations listing **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/translations/ + + .. code-tab:: python - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/translations/ + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/translations/' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response**: @@ -693,9 +870,20 @@ Redirect details **Example request** - .. sourcecode:: bash + .. tabs:: - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/redirects/1/ + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/redirects/1/ + + .. code-tab:: python + + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/redirects/1/' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response** @@ -724,9 +912,20 @@ Redirects listing **Example request** - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/redirects/ - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/redirects/ + .. code-tab:: python + + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/redirects/' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response** @@ -748,13 +947,27 @@ Redirect create **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl \ + -X POST \ + -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/redirects/ \ + -H "Content-Type: application/json" \ + -d @body.json + + .. code-tab:: python - $ curl \ - -X POST \ - -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/redirects/ \ - -H "Content-Type: application/json" \ - -d @body.json + import requests + import json + URL = 'https://readthedocs.org/api/v3/projects/pip/redirects/' + TOKEN = '' + HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + data = json.load(open('body.json', 'rb')) + response = requests.post(URL, + json = data, headers = HEADERS) + print(response.text) The content of ``body.json`` is like, @@ -792,13 +1005,27 @@ Redirect update **Example request**: - .. sourcecode:: bash + .. tabs:: - $ curl \ - -X PUT \ - -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/redirects/1/ \ - -H "Content-Type: application/json" \ - -d @body.json + .. code-tab:: bash + + $ curl \ + -X PUT \ + -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/redirects/1/ \ + -H "Content-Type: application/json" \ + -d @body.json + + .. code-tab:: python + + import requests + import json + URL = 'https://readthedocs.org/api/v3/projects/pip/redirects/1/' + TOKEN = '' + HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + data = json.load(open('body.json', 'rb')) + response = requests.put(URL, + json = data, headers = HEADERS) + print(response.text) The content of ``body.json`` is like, @@ -823,11 +1050,22 @@ Redirect delete **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl \ + -X DELETE \ + -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/redirects/1/ - $ curl \ - -X DELETE \ - -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/redirects/1/ + .. code-tab:: python + + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/redirects/1/' + TOKEN = '' + HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + response = requests.delete(URL, headers = HEADERS) + print(response.text) :statuscode 204: Redirect deleted successfully @@ -850,9 +1088,20 @@ Environment Variable details **Example request** - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/environmentvariables/1/ + + .. code-tab:: python - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/environmentvariables/1/ + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/environmentvariables/1/' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response** @@ -879,9 +1128,20 @@ Environment Variables listing **Example request** - .. sourcecode:: bash + .. tabs:: - $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/environmentvariables/ + .. code-tab:: bash + + $ curl -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/environmentvariables/ + + .. code-tab:: python + + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/environmentvariables/' + TOKEN = '' + HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + response = requests.get(URL, headers=HEADERS) + print(response.text) **Example response** @@ -903,13 +1163,27 @@ Environment Variable create **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl \ + -X POST \ + -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/environmentvariables/ \ + -H "Content-Type: application/json" \ + -d @body.json - $ curl \ - -X POST \ - -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/environmentvariables/ \ - -H "Content-Type: application/json" \ - -d @body.json + .. code-tab:: python + + import requests + import json + URL = 'https://readthedocs.org/api/v3/projects/pip/environmentvariables/' + TOKEN = '' + HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + data = json.load(open('body.json', 'rb')) + response = requests.post(URL, + json = data, headers = HEADERS) + print(response.text) The content of ``body.json`` is like, @@ -936,11 +1210,22 @@ Environment Variable delete **Example request**: - .. sourcecode:: bash + .. tabs:: + + .. code-tab:: bash + + $ curl \ + -X DELETE \ + -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/environmentvariables/1/ + + .. code-tab:: python - $ curl \ - -X DELETE \ - -H "Authorization: Token " https://readthedocs.org/api/v3/projects/pip/environmentvariables/1/ + import requests + URL = 'https://readthedocs.org/api/v3/projects/pip/environmentvariables/1/' + TOKEN = '' + HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + response = requests.delete(URL, headers = HEADERS) + print(response.text) :requestheader Authorization: token to authenticate. diff --git a/docs/conf.py b/docs/conf.py index cd28af13a32..83c366bf4c3 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -39,6 +39,7 @@ def get_version(): 'recommonmark', 'notfound.extension', 'sphinx_search.extension', + 'sphinx_tabs.tabs', ] templates_path = ['_templates'] From d01c23a8a33f3308ebebfb496fbbefcddf442231 Mon Sep 17 00:00:00 2001 From: dibyaaaaax Date: Fri, 10 Jan 2020 19:20:27 +0530 Subject: [PATCH 2/4] "made required changes" --- docs/api/v3.rst | 131 ++++++++++++++++++++++++++++-------------------- docs/conf.py | 1 - 2 files changed, 76 insertions(+), 56 deletions(-) diff --git a/docs/api/v3.rst b/docs/api/v3.rst index 3620d9275a3..580bad0f79d 100644 --- a/docs/api/v3.rst +++ b/docs/api/v3.rst @@ -91,9 +91,9 @@ Projects list import requests URL = 'https://readthedocs.org/api/v3/projects/' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response**: @@ -130,9 +130,9 @@ Project details import requests URL = 'https://readthedocs.org/api/v3/projects/pip/' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response**: @@ -224,9 +224,12 @@ Project create TOKEN = '' HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} data = json.load(open('body.json', 'rb')) - response = requests.post(URL, - json = data, headers = HEADERS) - print(response.text) + response = requests.post( + URL, + json=data, + headers=HEADERS, + ) + print(response.json()) The content of ``body.json`` is like, @@ -274,9 +277,12 @@ Project update TOKEN = '' HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} data = json.load(open('body.json', 'rb')) - response = requests.patch(URL, - json = data, headers = HEADERS) - print(response.text) + response = requests.patch( + URL, + json=data, + headers=HEADERS, + ) + print(response.json()) The content of ``body.json`` is like, @@ -333,9 +339,9 @@ Versions listing import requests URL = 'https://readthedocs.org/api/v3/projects/pip/versions/' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response**: @@ -372,9 +378,9 @@ Version detail import requests URL = 'https://readthedocs.org/api/v3/projects/pip/versions/stable/' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response**: @@ -442,9 +448,12 @@ Version update TOKEN = '' HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} data = json.load(open('body.json', 'rb')) - response = requests.patch(URL, - json = data, headers = HEADERS) - print(response.text) + response = requests.patch( + URL, + json=data, + headers=HEADERS, + ) + print(response.json()) The content of ``body.json`` is like, @@ -490,9 +499,9 @@ Build details import requests URL = 'https://readthedocs.org/api/v3/projects/pip/builds/8592686/?expand=config' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response**: @@ -585,9 +594,9 @@ Builds listing import requests URL = 'https://readthedocs.org/api/v3/projects/pip/builds/' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response**: @@ -628,8 +637,8 @@ Build triggering URL = 'https://readthedocs.org/api/v3/projects/pip/versions/latest/builds/' TOKEN = '' HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} - response = requests.post(URL, headers = HEADERS) - print(response.text) + response = requests.post(URL, headers=HEADERS) + print(response.json()) **Example response**: @@ -675,9 +684,9 @@ Subproject details import requests URL = 'https://readthedocs.org/api/v3/projects/pip/subprojects/subproject-alias/' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response**: @@ -713,9 +722,9 @@ Subprojects listing import requests URL = 'https://readthedocs.org/api/v3/projects/pip/subprojects/' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response**: @@ -757,9 +766,12 @@ Subproject create TOKEN = '' HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} data = json.load(open('body.json', 'rb')) - response = requests.post(URL, - json = data, headers = HEADERS) - print(response.text) + response = requests.post( + URL, + json = data, + headers=HEADERS, + ) + print(response.json()) The content of ``body.json`` is like, @@ -804,8 +816,8 @@ Subproject delete URL = 'https://readthedocs.org/api/v3/projects/pip/subprojects/subproject-alias/' TOKEN = '' HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} - response = requests.delete(URL, headers = HEADERS) - print(response.text) + response = requests.delete(URL, headers=HEADERS) + print(response.json()) :statuscode 204: Subproject deleted successfully @@ -837,9 +849,9 @@ Translations listing import requests URL = 'https://readthedocs.org/api/v3/projects/pip/translations/' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response**: @@ -881,9 +893,9 @@ Redirect details import requests URL = 'https://readthedocs.org/api/v3/projects/pip/redirects/1/' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response** @@ -923,9 +935,9 @@ Redirects listing import requests URL = 'https://readthedocs.org/api/v3/projects/pip/redirects/' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response** @@ -965,9 +977,12 @@ Redirect create TOKEN = '' HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} data = json.load(open('body.json', 'rb')) - response = requests.post(URL, - json = data, headers = HEADERS) - print(response.text) + response = requests.post( + URL, + json=data, + headers=HEADERS, + ) + print(response.json()) The content of ``body.json`` is like, @@ -1023,9 +1038,12 @@ Redirect update TOKEN = '' HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} data = json.load(open('body.json', 'rb')) - response = requests.put(URL, - json = data, headers = HEADERS) - print(response.text) + response = requests.put( + URL, + json=data, + headers=HEADERS, + ) + print(response.json()) The content of ``body.json`` is like, @@ -1064,8 +1082,8 @@ Redirect delete URL = 'https://readthedocs.org/api/v3/projects/pip/redirects/1/' TOKEN = '' HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} - response = requests.delete(URL, headers = HEADERS) - print(response.text) + response = requests.delete(URL, headers=HEADERS) + print(response.json()) :statuscode 204: Redirect deleted successfully @@ -1099,9 +1117,9 @@ Environment Variable details import requests URL = 'https://readthedocs.org/api/v3/projects/pip/environmentvariables/1/' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response** @@ -1139,9 +1157,9 @@ Environment Variables listing import requests URL = 'https://readthedocs.org/api/v3/projects/pip/environmentvariables/' TOKEN = '' - HEADERS = {'Authorization': 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.get(URL, headers=HEADERS) - print(response.text) + print(response.json()) **Example response** @@ -1181,9 +1199,12 @@ Environment Variable create TOKEN = '' HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} data = json.load(open('body.json', 'rb')) - response = requests.post(URL, - json = data, headers = HEADERS) - print(response.text) + response = requests.post( + URL, + json=data, + headers=HEADERS, + ) + print(response.json()) The content of ``body.json`` is like, @@ -1224,8 +1245,8 @@ Environment Variable delete URL = 'https://readthedocs.org/api/v3/projects/pip/environmentvariables/1/' TOKEN = '' HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} - response = requests.delete(URL, headers = HEADERS) - print(response.text) + response = requests.delete(URL, headers=HEADERS) + print(response.json()) :requestheader Authorization: token to authenticate. diff --git a/docs/conf.py b/docs/conf.py index 83c366bf4c3..cd28af13a32 100644 --- a/docs/conf.py +++ b/docs/conf.py @@ -39,7 +39,6 @@ def get_version(): 'recommonmark', 'notfound.extension', 'sphinx_search.extension', - 'sphinx_tabs.tabs', ] templates_path = ['_templates'] From 3c93bb506986f7b4b87d45bd95c2a3434701c06d Mon Sep 17 00:00:00 2001 From: dibyaaaaax Date: Tue, 14 Jan 2020 18:27:32 +0530 Subject: [PATCH 3/4] Change token formatting --- docs/api/v3.rst | 24 ++++++++++++------------ 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/docs/api/v3.rst b/docs/api/v3.rst index 580bad0f79d..3d5779a0b0c 100644 --- a/docs/api/v3.rst +++ b/docs/api/v3.rst @@ -222,7 +222,7 @@ Project create import json URL = 'https://readthedocs.org/api/v3/projects/' TOKEN = '' - HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} data = json.load(open('body.json', 'rb')) response = requests.post( URL, @@ -275,7 +275,7 @@ Project update import json URL = 'https://readthedocs.org/api/v3/projects/pip/' TOKEN = '' - HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} data = json.load(open('body.json', 'rb')) response = requests.patch( URL, @@ -446,7 +446,7 @@ Version update import json URL = 'https://readthedocs.org/api/v3/projects/pip/ersion/0.23/' TOKEN = '' - HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} data = json.load(open('body.json', 'rb')) response = requests.patch( URL, @@ -636,7 +636,7 @@ Build triggering import requests URL = 'https://readthedocs.org/api/v3/projects/pip/versions/latest/builds/' TOKEN = '' - HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.post(URL, headers=HEADERS) print(response.json()) @@ -764,11 +764,11 @@ Subproject create import json URL = 'https://readthedocs.org/api/v3/projects/pip/subprojects/' TOKEN = '' - HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} data = json.load(open('body.json', 'rb')) response = requests.post( URL, - json = data, + json=data, headers=HEADERS, ) print(response.json()) @@ -815,7 +815,7 @@ Subproject delete import requests URL = 'https://readthedocs.org/api/v3/projects/pip/subprojects/subproject-alias/' TOKEN = '' - HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.delete(URL, headers=HEADERS) print(response.json()) @@ -975,7 +975,7 @@ Redirect create import json URL = 'https://readthedocs.org/api/v3/projects/pip/redirects/' TOKEN = '' - HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} data = json.load(open('body.json', 'rb')) response = requests.post( URL, @@ -1036,7 +1036,7 @@ Redirect update import json URL = 'https://readthedocs.org/api/v3/projects/pip/redirects/1/' TOKEN = '' - HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} data = json.load(open('body.json', 'rb')) response = requests.put( URL, @@ -1081,7 +1081,7 @@ Redirect delete import requests URL = 'https://readthedocs.org/api/v3/projects/pip/redirects/1/' TOKEN = '' - HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.delete(URL, headers=HEADERS) print(response.json()) @@ -1197,7 +1197,7 @@ Environment Variable create import json URL = 'https://readthedocs.org/api/v3/projects/pip/environmentvariables/' TOKEN = '' - HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} data = json.load(open('body.json', 'rb')) response = requests.post( URL, @@ -1244,7 +1244,7 @@ Environment Variable delete import requests URL = 'https://readthedocs.org/api/v3/projects/pip/environmentvariables/1/' TOKEN = '' - HEADERS = {'Authorization' : 'token {}'.format(TOKEN)} + HEADERS = {'Authorization': f'token {TOKEN}'} response = requests.delete(URL, headers=HEADERS) print(response.json()) From 94e7fc1c8e4c885308daf649d8491613a3cf9a0b Mon Sep 17 00:00:00 2001 From: dibyaaaaax Date: Tue, 14 Jan 2020 23:15:37 +0530 Subject: [PATCH 4/4] Correct indentation --- docs/api/v3.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/api/v3.rst b/docs/api/v3.rst index 3d5779a0b0c..dc1360c3a47 100644 --- a/docs/api/v3.rst +++ b/docs/api/v3.rst @@ -1231,7 +1231,7 @@ Environment Variable delete **Example request**: - .. tabs:: + .. tabs:: .. code-tab:: bash