diff --git a/.gitignore b/.gitignore index fd06c94..d5bbe91 100644 --- a/.gitignore +++ b/.gitignore @@ -26,3 +26,4 @@ dist/* # Test Artifacts token_data.json +test_output.json \ No newline at end of file diff --git a/jobs/post/__init__.py b/jobs/post/__init__.py index 32a1ac2..3cea337 100644 --- a/jobs/post/__init__.py +++ b/jobs/post/__init__.py @@ -1,4 +1,6 @@ from .get import get from .listbybranch import listbybranch from .listbyuserprofile import listbyuserprofile -from .create import create \ No newline at end of file +from .create import create +from .listall import listall +from .listpublic import listpublic \ No newline at end of file diff --git a/jobs/post/listall.py b/jobs/post/listall.py new file mode 100644 index 0000000..0fe3da3 --- /dev/null +++ b/jobs/post/listall.py @@ -0,0 +1,11 @@ +def listall(API) -> dict: + """ + Fetches the list of posts for a given branch from the API. + + Args: + branch_slug (str): Slug of the branch to fetch posts for. + Returns: + dict: The list of posts for the branch. + """ + post_list = API.make_request("GET", "content", f"post", authenticate=True) + return post_list \ No newline at end of file diff --git a/jobs/post/listpublic.py b/jobs/post/listpublic.py new file mode 100644 index 0000000..53b6992 --- /dev/null +++ b/jobs/post/listpublic.py @@ -0,0 +1,11 @@ +def listpublic(API) -> dict: + """ + Fetches the list of public posts from the API. + + Args: + branch_slug (str): Slug of the branch to fetch posts for. + Returns: + dict: The list of public posts. + """ + post_list = API.make_request("GET", "content", f"post/public", authenticate=True) + return post_list \ No newline at end of file diff --git a/testing.py b/testing.py index 5526497..7095fe7 100644 --- a/testing.py +++ b/testing.py @@ -14,7 +14,7 @@ if not os.getenv("client_id") or not os.getenv("client_secret"): API = APIClient( client_id=os.getenv("client_id"), client_secret=os.getenv("client_secret"), - debug=True + debug=False # Set to True to enable debug output ) # Keep a token cache to avoid unnecessary sign-ins during development. @@ -29,7 +29,11 @@ if os.path.exists("token_data.json"): if not API.is_token_valid(): tokendata = API.sign_in() with open("token_data.json", "w") as f: - json.dump(tokendata, f, indent=4) + json.dump(tokendata, f, indent=2) + +def save_response(response): + with open("test_output.json", "w") as f: + json.dump(response, f, indent=2) # print("-----------Get a user profile----------------") # profile = API.run_job('userprofile.get', "simon-little") @@ -47,7 +51,8 @@ if not API.is_token_valid(): # feed = API.run_job('post.listbyuserprofile', "simon-little") # print(feed) # print("-----------------------------") -# post = API.run_job('post.create', { + +# save_response(API.run_job('post.create', { # "blurLabel": None, # "cardUrl": None, # "postText": "This is a test post created via the API wrapper.", @@ -56,11 +61,9 @@ if not API.is_token_valid(): # "pk": "maintrunk#maintrunk", # "sk": "maintrunk#maintrunk" # } -# }) -# print(post) -# print("-----------------------------") +# })) -# post = API.run_job('comment.create', { +# save_response(API.run_job('comment.create', { # "blurLabel": None, # "commentText": "This is a test comment created via the API wrapper.", # "parent": { @@ -73,12 +76,10 @@ if not API.is_token_valid(): # "sk": "post#1774951384-98fe38df" # }, # "version": 3 -# }) -# print(post) -# print("-----------------------------") -# feed = API.run_job('comment.listtbypostid', "1774951384-98fe38df") -# print(feed) -# print("-----------------------------") +# })) + +# save_response(API.run_job('comment.listtbypostid', "1774951384-98fe38df")) + # x = 1 # while x <= 20: # post = API.run_job('comment.create', { @@ -97,19 +98,17 @@ if not API.is_token_valid(): # }) # print(post) # x += 1 -# print("-----------------------------") -# notifications = API.run_job('notification.listnotifications') -# print(notifications) -# print("-----------------------------") -# feed = API.run_job('feed.cafefeed') -# print(feed) -# print("-----------------------------") -# feed = API.run_job('feed.followingfeed') -# print(feed) -# print("-----------------------------") -feed = API.run_job('feed.followingfeed', { - 'pk': 'maintrunk#maintrunk', - 'sk': 'post#1774951384-98fe38df' -}) -print(feed) -print("-----------------------------") \ No newline at end of file + +# save_response(API.run_job('notification.listnotifications')) + +# save_response(API.run_job('feed.cafefeed')) + +# save_response(API.run_job('feed.followingfeed')) + +# save_response(API.run_job('feed.followingfeed', { +# 'pk': 'maintrunk#maintrunk', +# 'sk': 'post#1774951384-98fe38df' +# })) + +save_response(API.run_job('post.listall')) + diff --git a/wrappers/__init__.py b/wrappers/__init__.py new file mode 100644 index 0000000..6a3cb9e --- /dev/null +++ b/wrappers/__init__.py @@ -0,0 +1 @@ +import post \ No newline at end of file diff --git a/wrappers/post.py b/wrappers/post.py new file mode 100644 index 0000000..6bd7ef3 --- /dev/null +++ b/wrappers/post.py @@ -0,0 +1,41 @@ +def create_post(post_text, parent_pksk="maintrunk#maintrunk", blur_label=None, card_url=None, collaborative=False): + """ + Creates a new post. + + Args: + post_text (str): The text content of the post. + parent_pksk (str): The parent PKSK for the post, default is "maintrunk#maintrunk". + blur_label (str, optional): An optional label for blurring the post content. + card_url (str, optional): An optional URL to include as a card in the post. + collaborative (bool, optional): Whether the post is collaborative, default is False. + + Returns: + dict: The response from the API containing details of the created post. + """ + + + + ''' + WIP + + How best to handle the API client here? + + - Should this be part of a big class? + - Should we pass the API client as an argument to this function? + - We can't create a new instance of the API client within this function + because it would need the credentials which can be dynamic and + don't want to tangle up this wrapper. + - + + ''' + response = API.run_job('post.create', { + "blurLabel": blur_label, + "cardUrl": card_url, + "postText": post_text, + "collaborative": collaborative, + "parent": { + "pk": parent_pksk, + "sk": parent_pksk + } + }) + return response \ No newline at end of file