Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 6ee6fc8b88 | |||
| 7d05b1c42c | |||
| b03c9738f1 |
+42
-28
@@ -2,9 +2,13 @@
|
|||||||
pydiscourse
|
pydiscourse
|
||||||
===========
|
===========
|
||||||
|
|
||||||
.. image:: https://github.com/bennylope/pydiscourse/workflows/Tests/badge.svg
|
.. image:: https://img.shields.io/pypi/v/pydiscourse?color=blue
|
||||||
|
:alt: PyPI
|
||||||
|
:target: https://pypi.org/project/pydiscourse/
|
||||||
|
|
||||||
|
.. image:: https://github.com/pydiscourse/pydiscourse/workflows/Tests/badge.svg
|
||||||
:alt: Build Status
|
:alt: Build Status
|
||||||
:target: https://github.com/bennylope/pydiscourse/actions
|
:target: https://github.com/pydiscourse/pydiscourse/actions
|
||||||
|
|
||||||
.. image:: https://img.shields.io/badge/Check%20out%20the-Docs-blue.svg
|
.. image:: https://img.shields.io/badge/Check%20out%20the-Docs-blue.svg
|
||||||
:alt: Check out the Docs
|
:alt: Check out the Docs
|
||||||
@@ -37,42 +41,52 @@ Installation
|
|||||||
Examples
|
Examples
|
||||||
========
|
========
|
||||||
|
|
||||||
Create a client connection to a Discourse server::
|
Create a client connection to a Discourse server:
|
||||||
|
|
||||||
from pydiscourse import DiscourseClient
|
.. code:: python
|
||||||
client = DiscourseClient(
|
|
||||||
'http://example.com',
|
|
||||||
api_username='username',
|
|
||||||
api_key='areallylongstringfromdiscourse')
|
|
||||||
|
|
||||||
Get info about a user::
|
from pydiscourse import DiscourseClient
|
||||||
|
client = DiscourseClient(
|
||||||
|
'http://example.com',
|
||||||
|
api_username='username',
|
||||||
|
api_key='areallylongstringfromdiscourse')
|
||||||
|
|
||||||
user = client.user('eviltrout')
|
Get info about a user:
|
||||||
print user
|
|
||||||
|
|
||||||
user_topics = client.topics_by('johnsmith')
|
.. code:: python
|
||||||
print user_topics
|
|
||||||
|
|
||||||
Create a new user::
|
user = client.user('eviltrout')
|
||||||
|
print user
|
||||||
|
|
||||||
user = client.create_user('The Black Knight', 'blacknight', 'knight@python.org', 'justafleshwound')
|
user_topics = client.topics_by('johnsmith')
|
||||||
|
print user_topics
|
||||||
|
|
||||||
Implement SSO for Discourse with your Python server::
|
Create a new user:
|
||||||
|
|
||||||
@login_required
|
.. code:: python
|
||||||
def discourse_sso_view(request):
|
|
||||||
payload = request.GET.get('sso')
|
user = client.create_user('The Black Knight', 'blacknight', 'knight@python.org', 'justafleshwound')
|
||||||
signature = request.GET.get('sig')
|
|
||||||
nonce = sso_validate(payload, signature, SECRET)
|
Implement SSO for Discourse with your Python server:
|
||||||
url = sso_redirect_url(nonce, SECRET, request.user.email, request.user.id, request.user.username)
|
|
||||||
return redirect('http://discuss.example.com' + url)
|
.. code:: python
|
||||||
|
|
||||||
|
@login_required
|
||||||
|
def discourse_sso_view(request):
|
||||||
|
payload = request.GET.get('sso')
|
||||||
|
signature = request.GET.get('sig')
|
||||||
|
nonce = sso_validate(payload, signature, SECRET)
|
||||||
|
url = sso_redirect_url(nonce, SECRET, request.user.email, request.user.id, request.user.username)
|
||||||
|
return redirect('http://discuss.example.com' + url)
|
||||||
|
|
||||||
Command line
|
Command line
|
||||||
============
|
============
|
||||||
|
|
||||||
To help experiment with the Discourse API, pydiscourse provides a simple command line client::
|
To help experiment with the Discourse API, pydiscourse provides a simple command line client:
|
||||||
|
|
||||||
export DISCOURSE_API_KEY=your_master_key
|
.. code:: bash
|
||||||
pydiscoursecli --host-http://yourhost --api-user-system latest_topics
|
|
||||||
pydiscoursecli --host-http://yourhost --api-user-system topics_by johnsmith
|
export DISCOURSE_API_KEY=your_master_key
|
||||||
pydiscoursecli --host-http://yourhost --api-user-system user eviltrout
|
pydiscoursecli --host-http://yourhost --api-user-system latest_topics
|
||||||
|
pydiscoursecli --host-http://yourhost --api-user-system topics_by johnsmith
|
||||||
|
pydiscoursecli --host-http://yourhost --api-user-system user eviltrout
|
||||||
|
|||||||
Reference in New Issue
Block a user