Compare commits

..

No commits in common. "master" and "use-discourse-request" have entirely different histories.

9 changed files with 38 additions and 97 deletions

View File

@ -13,7 +13,7 @@ jobs:
- name: Set up Python
uses: actions/setup-python@v2
with:
python-version: "3.12"
python-version: "3.11"
- 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", "3.12" ]
python-version: [ "3.8", "3.9", "3.10", "3.11" ]
steps:
- uses: actions/checkout@v1

View File

@ -3,19 +3,6 @@
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,13 +2,9 @@
pydiscourse
===========
.. 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
.. image:: https://github.com/bennylope/pydiscourse/workflows/Tests/badge.svg
:alt: Build Status
:target: https://github.com/pydiscourse/pydiscourse/actions
:target: https://github.com/bennylope/pydiscourse/actions
.. image:: https://img.shields.io/badge/Check%20out%20the-Docs-blue.svg
:alt: Check out the Docs
@ -41,52 +37,42 @@ Installation
Examples
========
Create a client connection to a Discourse server:
Create a client connection to a Discourse server::
.. code:: python
from pydiscourse import DiscourseClient
client = DiscourseClient(
'http://example.com',
api_username='username',
api_key='areallylongstringfromdiscourse')
from pydiscourse import DiscourseClient
client = DiscourseClient(
'http://example.com',
api_username='username',
api_key='areallylongstringfromdiscourse')
Get info about a user::
Get info about a user:
user = client.user('eviltrout')
print user
.. code:: python
user_topics = client.topics_by('johnsmith')
print user_topics
user = client.user('eviltrout')
print user
Create a new user::
user_topics = client.topics_by('johnsmith')
print user_topics
user = client.create_user('The Black Knight', 'blacknight', 'knight@python.org', 'justafleshwound')
Create a new user:
Implement SSO for Discourse with your Python server::
.. 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)
@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::
.. 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
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.7'
version = '1.6'
# The full version, including alpha/beta/rc tags.
release = '1.7.0'
release = '1.6.0'
# The language for content autogenerated by Sphinx. Refer to documentation
# for a list of supported languages.

View File

@ -29,7 +29,6 @@ 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.7.0"
__version__ = "1.6.0"
from pydiscourse.client import DiscourseClient

View File

@ -230,17 +230,6 @@ 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
@ -855,17 +844,17 @@ class DiscourseClient:
kwargs = {"email": user_email, "topic_id": topic_id}
return self._post(f"/t/{topic_id}/invite.json", **kwargs)
def search(self, q, **kwargs):
def search(self, term, **kwargs):
"""
Args:
q:
term:
**kwargs:
Returns:
"""
kwargs["q"] = q
kwargs["term"] = term
return self._get("/search.json", **kwargs)
def badges(self, **kwargs):
@ -1511,12 +1500,6 @@ 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,12 +83,6 @@ 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")
@ -172,8 +166,8 @@ class TestPosts:
class TestSearch:
def test_search(self, discourse_client, discourse_request):
request = discourse_request("get", "/search.json?q=needle")
discourse_client.search(q="needle")
request = discourse_request("get", "/search.json?term=needle")
discourse_client.search(term="needle")
assert request.called_once
@ -211,10 +205,3 @@ 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,7 +7,6 @@ python =
3.9: py39
3.10: py310
3.11: py311
3.12: py312
[testenv]
setenv =