Compare commits
13 Commits
use-discou
...
master
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
6ee6fc8b88 | ||
|
|
7d05b1c42c | ||
|
|
b03c9738f1 | ||
|
|
36f8f1e737 | ||
|
|
2d27cc2a3c | ||
|
|
f81c1b775a | ||
|
|
270f4bbbdb | ||
|
|
7d981684aa | ||
|
|
53be265b23 | ||
|
|
a07b122c39 | ||
|
|
6d54153a24 | ||
|
|
c30a453a6b | ||
|
|
3e87ef3849 |
4
.github/workflows/test.yml
vendored
4
.github/workflows/test.yml
vendored
@ -13,7 +13,7 @@ jobs:
|
||||
- name: Set up Python
|
||||
uses: actions/setup-python@v2
|
||||
with:
|
||||
python-version: "3.11"
|
||||
python-version: "3.12"
|
||||
|
||||
- name: Install dependencies
|
||||
run: |
|
||||
@ -31,7 +31,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
strategy:
|
||||
matrix:
|
||||
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
|
||||
python-version: [ "3.8", "3.9", "3.10", "3.11", "3.12" ]
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v1
|
||||
|
||||
13
HISTORY.rst
13
HISTORY.rst
@ -3,6 +3,19 @@
|
||||
Release history
|
||||
===============
|
||||
|
||||
|
||||
1.7.0
|
||||
-----
|
||||
|
||||
- Possible breaking change: Change `search()` term paramater from `term` to `q`,
|
||||
fixes search. Thanks @weber-s
|
||||
- Add support for Python 3.12
|
||||
|
||||
1.6.1
|
||||
-----
|
||||
|
||||
- Adds `posts_by_number` endpoint from @Dettorer
|
||||
|
||||
1.6.0
|
||||
-----
|
||||
|
||||
|
||||
70
README.rst
70
README.rst
@ -2,9 +2,13 @@
|
||||
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
|
||||
: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
|
||||
:alt: Check out the Docs
|
||||
@ -37,42 +41,52 @@ Installation
|
||||
Examples
|
||||
========
|
||||
|
||||
Create a client connection to a Discourse server::
|
||||
Create a client connection to a Discourse server:
|
||||
|
||||
from pydiscourse import DiscourseClient
|
||||
client = DiscourseClient(
|
||||
'http://example.com',
|
||||
api_username='username',
|
||||
api_key='areallylongstringfromdiscourse')
|
||||
.. code:: python
|
||||
|
||||
Get info about a user::
|
||||
from pydiscourse import DiscourseClient
|
||||
client = DiscourseClient(
|
||||
'http://example.com',
|
||||
api_username='username',
|
||||
api_key='areallylongstringfromdiscourse')
|
||||
|
||||
user = client.user('eviltrout')
|
||||
print user
|
||||
Get info about a user:
|
||||
|
||||
user_topics = client.topics_by('johnsmith')
|
||||
print user_topics
|
||||
.. code:: python
|
||||
|
||||
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
|
||||
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)
|
||||
.. code:: python
|
||||
|
||||
user = client.create_user('The Black Knight', 'blacknight', 'knight@python.org', 'justafleshwound')
|
||||
|
||||
Implement SSO for Discourse with your Python server:
|
||||
|
||||
.. 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
|
||||
============
|
||||
|
||||
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
|
||||
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
|
||||
.. code:: bash
|
||||
|
||||
export DISCOURSE_API_KEY=your_master_key
|
||||
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
|
||||
|
||||
@ -51,9 +51,9 @@ copyright = u'2014, Marc Sibson'
|
||||
# built documents.
|
||||
#
|
||||
# The short X.Y version.
|
||||
version = '1.6'
|
||||
version = '1.7'
|
||||
# The full version, including alpha/beta/rc tags.
|
||||
release = '1.6.0'
|
||||
release = '1.7.0'
|
||||
|
||||
# The language for content autogenerated by Sphinx. Refer to documentation
|
||||
# for a list of supported languages.
|
||||
|
||||
@ -29,6 +29,7 @@ classifiers =
|
||||
Programming Language :: Python :: 3.9
|
||||
Programming Language :: Python :: 3.10
|
||||
Programming Language :: Python :: 3.11
|
||||
Programming Language :: Python :: 3.12
|
||||
|
||||
[options.packages.find]
|
||||
where=src
|
||||
|
||||
@ -1,6 +1,6 @@
|
||||
"""Python client for the Discourse API."""
|
||||
|
||||
__version__ = "1.6.0"
|
||||
__version__ = "1.7.0"
|
||||
|
||||
from pydiscourse.client import DiscourseClient
|
||||
|
||||
|
||||
@ -230,6 +230,17 @@ class DiscourseClient:
|
||||
"""
|
||||
return self._put(f"/admin/users/{userid}/trust_level", level=level)
|
||||
|
||||
def anonymize(self, userid):
|
||||
"""
|
||||
|
||||
Args:
|
||||
userid: the Discourse user ID
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
return self._put(f"/admin/users/{userid}/anonymize")
|
||||
|
||||
def suspend(self, userid, duration, reason):
|
||||
"""
|
||||
Suspend a user's account
|
||||
@ -844,17 +855,17 @@ class DiscourseClient:
|
||||
kwargs = {"email": user_email, "topic_id": topic_id}
|
||||
return self._post(f"/t/{topic_id}/invite.json", **kwargs)
|
||||
|
||||
def search(self, term, **kwargs):
|
||||
def search(self, q, **kwargs):
|
||||
"""
|
||||
|
||||
Args:
|
||||
term:
|
||||
q:
|
||||
**kwargs:
|
||||
|
||||
Returns:
|
||||
|
||||
"""
|
||||
kwargs["term"] = term
|
||||
kwargs["q"] = q
|
||||
return self._get("/search.json", **kwargs)
|
||||
|
||||
def badges(self, **kwargs):
|
||||
@ -1500,6 +1511,12 @@ class DiscourseClient:
|
||||
"""
|
||||
return self._post(f"/category/{category_id}/notifications", **kwargs)
|
||||
|
||||
def about(self):
|
||||
"""
|
||||
Get site info
|
||||
"""
|
||||
return self._get("/about.json")
|
||||
|
||||
def _get(self, path, override_request_kwargs=None, **kwargs):
|
||||
"""
|
||||
|
||||
|
||||
@ -83,6 +83,12 @@ class TestUserManagement:
|
||||
|
||||
assert request.called_once
|
||||
|
||||
def test_anonymize(self, discourse_client, discourse_request):
|
||||
request = discourse_request("put", "/admin/users/123/anonymize")
|
||||
discourse_client.anonymize(123)
|
||||
|
||||
assert request.called_once
|
||||
|
||||
@pytest.mark.usefixtures("_frozen_time")
|
||||
def test_suspend_user(self, discourse_client, discourse_request):
|
||||
request = discourse_request("put", "/admin/users/123/suspend")
|
||||
@ -166,8 +172,8 @@ class TestPosts:
|
||||
|
||||
class TestSearch:
|
||||
def test_search(self, discourse_client, discourse_request):
|
||||
request = discourse_request("get", "/search.json?term=needle")
|
||||
discourse_client.search(term="needle")
|
||||
request = discourse_request("get", "/search.json?q=needle")
|
||||
discourse_client.search(q="needle")
|
||||
assert request.called_once
|
||||
|
||||
|
||||
@ -205,3 +211,10 @@ class TestBadges:
|
||||
|
||||
assert request_payload["username"] == ["username"]
|
||||
assert request_payload["badge_id"] == ["1"]
|
||||
|
||||
|
||||
class TestAbout:
|
||||
def test_about(self, discourse_client, discourse_request):
|
||||
request = discourse_request("get", "/about.json")
|
||||
discourse_client.about()
|
||||
assert request.called_once
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user