From 620553ea14da8e00d3d31f1388e80c39745947f8 Mon Sep 17 00:00:00 2001 From: simonwt Date: Tue, 31 Mar 2026 12:00:49 +0100 Subject: [PATCH] Comment create --- README.md | 23 ++++++++++++++++------- jobs/comment/__init__.py | 1 + jobs/comment/create.py | 13 +++++++++++++ testing.py | 35 ++++++++++++++++++++++++++--------- 4 files changed, 56 insertions(+), 16 deletions(-) create mode 100644 jobs/comment/__init__.py create mode 100644 jobs/comment/create.py diff --git a/README.md b/README.md index 2c9ec10..80bc5f8 100644 --- a/README.md +++ b/README.md @@ -2,15 +2,24 @@ Intended use (not working yet but testing.py does) -''' -import trustcafeapi -import os, simplejson as json +```python +import trustcafeapiwrapper, os -API = trustcafeapi.APIClient( +API = trustcafeapiwrapper.APIClient( client_id=os.getenv("client_id"), - client_secret=os.getenv("client_secret"), - debug=True + client_secret=os.getenv("client_secret") ) -''' \ No newline at end of file +profile = API.run_job('userprofile.get', "simon-little") +``` + +## Debates + +1. Not sure about the name `jobs` and `run_job`. Requests is an +existing package dependency though. `tasks` seems to broard. I'm sure +there's probably an already existing name that I can't articulate how +to find. +2. Should these `job` be called with dot notation? Or with slashes? Or +something else? Is it okay to have these as strings? +3. Should we do validation in the `jobs` or let the server do that all? \ No newline at end of file diff --git a/jobs/comment/__init__.py b/jobs/comment/__init__.py new file mode 100644 index 0000000..fd01b16 --- /dev/null +++ b/jobs/comment/__init__.py @@ -0,0 +1 @@ +from .create import create \ No newline at end of file diff --git a/jobs/comment/create.py b/jobs/comment/create.py new file mode 100644 index 0000000..719d108 --- /dev/null +++ b/jobs/comment/create.py @@ -0,0 +1,13 @@ +def create(API, payload: dict) -> dict: + """ + Creates a new comment in the API. + + Args: + payload (dict): The data for the new post. + + Returns: + dict: The comment data. + """ + print(f"Creating a new comment with payload: {payload}") + comment_data = API.make_request("POST", "content", "commentcreate", data=payload, authenticate=True) + return comment_data \ No newline at end of file diff --git a/testing.py b/testing.py index 84bc226..387cfae 100644 --- a/testing.py +++ b/testing.py @@ -31,12 +31,13 @@ if not API.is_token_valid(): with open("token_data.json", "w") as f: json.dump(tokendata, f, indent=4) +# print("-----------Get a user profile----------------") # profile = API.run_job('userprofile.get', "simon-little") # print(profile) -# print("-----------------------------") +# print("-------------- Get a branch -----------------") # branch = API.run_job('branch.get', "music") # print(branch) -# print("-----------------------------") +# print("-------------- Get a post -------------------") # post = API.run_job('post.get', "1774875037-170a46a9") # print(post) # print("-----------------------------") @@ -45,15 +46,31 @@ if not API.is_token_valid(): # print("-----------------------------") # feed = API.run_job('post.listbyuserprofile', "simon-little") # print(feed) -print("-----------------------------") -post = API.run_job('post.create', { +# print("-----------------------------") +# post = API.run_job('post.create', { +# "blurLabel": None, +# "cardUrl": None, +# "postText": "This is a test post created via the API wrapper.", +# "collaborative": False, +# "parent": { +# "pk": "maintrunk#maintrunk", +# "sk": "maintrunk#maintrunk" +# } +# }) +# print(post) +# print("-----------------------------") +post = API.run_job('comment.create', { "blurLabel": None, - "cardUrl": None, - "postText": "This is a test post created via the API wrapper.", - "collaborative": False, + "commentText": "This is a test comment created via the API wrapper.", "parent": { "pk": "maintrunk#maintrunk", - "sk": "maintrunk#maintrunk" - } + "sk": "post#1774951384-98fe38df", + "slug": "1774951384-98fe38df" + }, + "topLevel": { + "pk": "maintrunk#maintrunk", + "sk": "post#1774951384-98fe38df" + }, + "version": 3 }) print(post) \ No newline at end of file