diff --git a/README.md b/README.md index 7d53f65..81acd29 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ 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? +4. `wrapped` is an awkward name. What's more proper? But also obvious? ## ToDo: diff --git a/apiclient.py b/apiclient.py index 52731bb..c8134fe 100644 --- a/apiclient.py +++ b/apiclient.py @@ -146,4 +146,19 @@ class APIClient(BaseModel): job_func = job_function return job_func(self, *args, **kwargs) + + def wrapped(self, wrapped_data): + """ + Utility method to run a job function based on a wrapped data dictionary + containing 'job' and 'payload' keys as expected by the API client wrapper functions. + Args: + wrapped_data (dict): A dictionary with 'job' (string) and 'payload' (dict) keys. + Returns: + The result of the job function execution. + + + """ + + return self.run_job(wrapped_data.get("job_function"), wrapped_data.get("payload", {})) + diff --git a/jobs/post/listallrename.py b/jobs/post/listallrename.py new file mode 100644 index 0000000..53b6992 --- /dev/null +++ b/jobs/post/listallrename.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 e0fe060..9da9e85 100644 --- a/testing.py +++ b/testing.py @@ -127,7 +127,12 @@ from wrappers.post.create_post import create_post # "This is a test post created via the create_post wrapper function.", # "/userprofile/simon-little", # )) -save_response(API.run_job('post.create', create_post( + +# wrapped = create_post( +# "This is a test post created via the create_post wrapper function without using the `wrapped` method.", +# ) +# save_response(API.run_job(**wrapped)) + +save_response(API.wrapped(create_post( "This is a test post created via the create_post wrapper function.", - "/userprofile/simon-little", -))) +))) \ No newline at end of file diff --git a/wrappers/post/create_post.py b/wrappers/post/create_post.py index d667a41..5e45012 100644 --- a/wrappers/post/create_post.py +++ b/wrappers/post/create_post.py @@ -10,8 +10,8 @@ def create_post(post_text, parent_path='/', blur_label=None, card_url=None, coll collaborative (bool, optional): Whether the post is collaborative, default is False. Returns: - dict: The payload for creating the post, which can be passed to - the API client's run_job method with 'post.create'. + dict: A dictionary containing the job name and payload for creating the post + that will be processed by the API client wrapper function. """ parent_pksk = None @@ -32,12 +32,15 @@ def create_post(post_text, parent_path='/', blur_label=None, card_url=None, coll return { - "blurLabel": blur_label, - "cardUrl": card_url, - "postText": post_text, - "collaborative": collaborative, - "parent": { - "pk": parent_pksk, - "sk": parent_pksk - } - } \ No newline at end of file + "job_function": "post.create", + "payload": { + "blurLabel": blur_label, + "cardUrl": card_url, + "postText": post_text, + "collaborative": collaborative, + "parent": { + "pk": parent_pksk, + "sk": parent_pksk + } + } + } \ No newline at end of file