Skip to content

Add python examples for API v3 Documentation #6487

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jan 22, 2020

Conversation

dibyaaaaax
Copy link
Contributor

No description provided.

@dibyaaaaax
Copy link
Contributor Author

Issue #5935

Copy link
Member

@stsewd stsewd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, code looks good. Left some suggestions

docs/api/v3.rst Outdated
TOKEN = '<token>'
HEADERS = {'Authorization': 'token {}'.format(TOKEN)}
response = requests.get(URL, headers=HEADERS)
print(response.text)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(response.text)
print(response.json())

docs/api/v3.rst Outdated
import requests
URL = 'https://readthedocs.org/api/v3/projects/'
TOKEN = '<token>'
HEADERS = {'Authorization': 'token {}'.format(TOKEN)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
HEADERS = {'Authorization': 'token {}'.format(TOKEN)}
HEADERS = {'Authorization': f'token {TOKEN}'}

docs/api/v3.rst Outdated
import requests
URL = 'https://readthedocs.org/api/v3/projects/pip/'
TOKEN = '<token>'
HEADERS = {'Authorization': 'token {}'.format(TOKEN)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
HEADERS = {'Authorization': 'token {}'.format(TOKEN)}
HEADERS = {'Authorization': f'token {TOKEN}'}

docs/api/v3.rst Outdated
TOKEN = '<token>'
HEADERS = {'Authorization': 'token {}'.format(TOKEN)}
response = requests.get(URL, headers=HEADERS)
print(response.text)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(response.text)
print(response.json())

docs/api/v3.rst Outdated
import json
URL = 'https://readthedocs.org/api/v3/projects/'
TOKEN = '<token>'
HEADERS = {'Authorization' : 'token {}'.format(TOKEN)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
HEADERS = {'Authorization' : 'token {}'.format(TOKEN)}
HEADERS = {'Authorization' : f'token {TOKEN}'}

docs/api/v3.rst Outdated
TOKEN = '<token>'
HEADERS = {'Authorization': 'token {}'.format(TOKEN)}
response = requests.get(URL, headers=HEADERS)
print(response.text)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(response.text)
print(response.json())

docs/api/v3.rst Outdated
HEADERS = {'Authorization' : 'token {}'.format(TOKEN)}
data = json.load(open('body.json', 'rb'))
response = requests.post(URL,
json = data, headers = HEADERS)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same about indentation

docs/api/v3.rst Outdated
import json
URL = 'https://readthedocs.org/api/v3/projects/pip/redirects/'
TOKEN = '<token>'
HEADERS = {'Authorization' : 'token {}'.format(TOKEN)}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
HEADERS = {'Authorization' : 'token {}'.format(TOKEN)}
HEADERS = {'Authorization' : f'token {TOKEN}'}

docs/api/v3.rst Outdated
data = json.load(open('body.json', 'rb'))
response = requests.post(URL,
json = data, headers = HEADERS)
print(response.text)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
print(response.text)
print(response.json())

docs/conf.py Outdated
@@ -39,6 +39,7 @@ def get_version():
'recommonmark',
'notfound.extension',
'sphinx_search.extension',
'sphinx_tabs.tabs',
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We already have this extension listed above ^

Suggested change
'sphinx_tabs.tabs',

Copy link
Member

@stsewd stsewd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are still some places where we need to change from 'token {}'.format(TOKEN) to f'token {TOKEN}'

docs/api/v3.rst Outdated
data = json.load(open('body.json', 'rb'))
response = requests.post(
URL,
json = data,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
json = data,
json=data,

Copy link
Member

@stsewd stsewd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The last example looks broken, I think it may be the indentation
Screenshot_2020-01-14 API v3 — Read the Docs 3 11 1 documentation

docs/api/v3.rst Outdated
@@ -936,11 +1231,22 @@ Environment Variable delete

**Example request**:

.. sourcecode:: bash
.. tabs::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
.. tabs::
.. tabs::

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sorry about that, must have missed the last one while checking. I fixed it.

Copy link
Member

@stsewd stsewd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks great, thanks!

@stsewd stsewd merged commit 2e93c5f into readthedocs:master Jan 22, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants