Fix public
Add guest alternative Write some doc
This commit is contained in:
parent
eabca3e7bf
commit
ae6ee7e7a0
4 changed files with 94 additions and 16 deletions
|
|
@ -1,18 +1,93 @@
|
|||
# Basic usage (without an .env)
|
||||
## Setup
|
||||
Here's how to make a post to the homepage (aka Maintrunk)
|
||||
|
||||
```python
|
||||
import trustcafeapiwrapper
|
||||
from trustcafeapiwrapper.wrappers.post.create_post import create_post
|
||||
|
||||
# Setup the API Client
|
||||
API = trustcafeapiwrapper.APIClient(
|
||||
client_id="YOUR_CLIENT_ID"
|
||||
client_secret="YOUR_CLIENT_SECRET"
|
||||
)
|
||||
```
|
||||
## Use a wrapper
|
||||
Wrappers make it as simple as possible to perform an action.
|
||||
|
||||
A wrapper will come with a job and a payload ready to be passed to the `wrapped` function.
|
||||
|
||||
eg. Use the `create_post` wrapper
|
||||
|
||||
```python
|
||||
from trustcafeapiwrapper.wrappers.post.create_post import create_post
|
||||
|
||||
# Use the create_post wrapper
|
||||
API.wrapped(create_post(
|
||||
"This is a test post created via the create_post wrapper function.",
|
||||
))
|
||||
```
|
||||
|
||||
|
||||
**_NOTE:_** There are not as many wrappers as jobs because fetching is simpler. More will be added though to make it consistent.
|
||||
|
||||
|
||||
## Make a request via `job`
|
||||
Jobs make the requests to the API. They have the endpoint and path setup already, we just pass the payload. If you want to avoid making your own payload, use a `wrapper`.
|
||||
|
||||
Use the job for getting public posts.
|
||||
|
||||
Now you don't need to worry about which API
|
||||
```python
|
||||
postlist = API.run_job('posts.getpublic')
|
||||
print(postlist)
|
||||
'''
|
||||
{
|
||||
"Items": [
|
||||
{
|
||||
...
|
||||
'''
|
||||
```
|
||||
**_NOTE:_** There are aren't the complete set yet created here.
|
||||
|
||||
## Custom Request
|
||||
There should hopefully be a `job` or a `wrapper` that exists for what you need but if not, then this is how you make a request using the core mechanism.
|
||||
|
||||
Use the `make_request` function to make a request from the content API to get posts in the music branch.
|
||||
```python
|
||||
postlist = API.make_request("GET", "content", f"post/ref-subwiki/music")
|
||||
print(postlist)
|
||||
'''
|
||||
{
|
||||
"Items": [
|
||||
{
|
||||
...
|
||||
'''
|
||||
```
|
||||
|
||||
# Jobs
|
||||
## block
|
||||
## branch
|
||||
### `get`
|
||||
### `listbyname`
|
||||
## change
|
||||
## comment
|
||||
### `create`
|
||||
### `listbypostid`
|
||||
## feed
|
||||
## mute
|
||||
## notifcation
|
||||
### `listnotifications`
|
||||
## post
|
||||
## reaction
|
||||
## trust
|
||||
## userprofile
|
||||
## vote
|
||||
|
||||
|
||||
# Wrappers
|
||||
## post
|
||||
### `create_post`
|
||||
### `update_post`
|
||||
## comment
|
||||
### `create_comment`
|
||||
|
||||
# Utils
|
||||
|
|
@ -61,13 +61,16 @@ class APIClient(BaseModel):
|
|||
url += f"?{urlencode(query_params)}"
|
||||
|
||||
# Set up headers for the request
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
}
|
||||
# Add the Authorization header with the access token if authentication is required
|
||||
if authenticate:
|
||||
token = self._access_token
|
||||
headers["Authorization"] = f"Bearer {token}"
|
||||
else:
|
||||
token = 'guest'
|
||||
|
||||
headers = {
|
||||
"Content-Type": "application/json",
|
||||
"Authorization": f"Bearer {token}"
|
||||
}
|
||||
|
||||
|
||||
# Debugging output to show the request details before making the API call
|
||||
if self.debug:
|
||||
|
|
|
|||
|
|
@ -7,5 +7,5 @@ def listpublic(API, lastEvaluatedKey=None) -> dict:
|
|||
Returns:
|
||||
dict: The list of public posts.
|
||||
"""
|
||||
post_list = API.make_request("GET", "content", f"post/public", authenticate=True, query_params=lastEvaluatedKey)
|
||||
post_list = API.make_request("GET", "content", f"public/posts", authenticate=False, query_params=lastEvaluatedKey)
|
||||
return post_list
|
||||
14
testing.py
14
testing.py
|
|
@ -149,7 +149,7 @@ def save_response(response):
|
|||
# }))
|
||||
|
||||
# save_response(API.run_job('post.listall'))
|
||||
# save_response(API.run_job('post.listpublic'))
|
||||
save_response(API.run_job('post.listpublic'))
|
||||
|
||||
# from trustcafeapiwrapper.wrappers.post.create_post import create_post
|
||||
|
||||
|
|
@ -199,9 +199,9 @@ def save_response(response):
|
|||
# "/user/bossman"
|
||||
# )))
|
||||
|
||||
from trustcafeapiwrapper.wrappers.post.update_post import update_post
|
||||
save_response(API.wrapped(update_post(
|
||||
post_text="This is an updated version of the test post created via the create_post wrapper function.",
|
||||
post_path="/post/1775143460-ef45186a",
|
||||
parent_path="/",
|
||||
)))
|
||||
# from trustcafeapiwrapper.wrappers.post.update_post import update_post
|
||||
# save_response(API.wrapped(update_post(
|
||||
# post_text="This is an updated version of the test post created via the create_post wrapper function.",
|
||||
# post_path="/post/1775143460-ef45186a",
|
||||
# parent_path="/",
|
||||
# )))
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue