Compare commits

...

13 Commits

Author SHA1 Message Date
Samuël WEBER
6ee6fc8b88 docs: rename bennylope -> pydiscourse in readme 2025-02-25 11:33:51 -05:00
Samuël WEBER
7d05b1c42c docs: add pypi badge in readme 2025-02-25 11:33:51 -05:00
Samuël WEBER
b03c9738f1 docs: readme code highlighted 2025-02-25 11:33:29 -05:00
Ben Lopatin
36f8f1e737
Merge pull request #93 from pydiscourse/v1.7
Bump version
2024-04-16 16:34:57 -04:00
Ben Lopatin
2d27cc2a3c Update History 2024-04-16 16:32:22 -04:00
Ben Lopatin
f81c1b775a Add support for Python 3.12 2024-04-16 16:31:58 -04:00
Ben Lopatin
270f4bbbdb Bump version 2024-04-16 16:31:17 -04:00
Samuël WEBER
7d981684aa add anonymize endpoint 2024-02-24 13:26:43 -05:00
Samuël WEBER
53be265b23 fix: search term moved to q 2023-09-27 11:17:01 -04:00
Samuël WEBER
a07b122c39 add about endpoint for site statistics 2023-09-07 10:57:28 -04:00
Ben Lopatin
6d54153a24
Merge pull request #90 from pydiscourse/new-version
Update version for release
2023-09-01 10:37:25 -04:00
Ben Lopatin
c30a453a6b Bump version 2023-09-01 10:35:28 -04:00
Ben Lopatin
3e87ef3849
Merge pull request #89 from pydiscourse/use-discourse-request
Replace mocks and increase coverage requirement
2023-09-01 10:23:50 -04:00
9 changed files with 97 additions and 38 deletions

View File

@ -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

View File

@ -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
-----

View File

@ -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

View File

@ -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.

View File

@ -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

View File

@ -1,6 +1,6 @@
"""Python client for the Discourse API."""
__version__ = "1.6.0"
__version__ = "1.7.0"
from pydiscourse.client import DiscourseClient

View File

@ -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):
"""

View File

@ -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

View File

@ -7,6 +7,7 @@ python =
3.9: py39
3.10: py310
3.11: py311
3.12: py312
[testenv]
setenv =