wrapped function to condense code
This commit is contained in:
parent
7fa6d640e4
commit
c27a89b8f9
5 changed files with 49 additions and 14 deletions
|
|
@ -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:
|
||||
|
||||
|
|
|
|||
15
apiclient.py
15
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", {}))
|
||||
|
||||
|
||||
|
|
|
|||
11
jobs/post/listallrename.py
Normal file
11
jobs/post/listallrename.py
Normal file
|
|
@ -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
|
||||
11
testing.py
11
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",
|
||||
)))
|
||||
)))
|
||||
|
|
@ -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
|
||||
}
|
||||
}
|
||||
"job_function": "post.create",
|
||||
"payload": {
|
||||
"blurLabel": blur_label,
|
||||
"cardUrl": card_url,
|
||||
"postText": post_text,
|
||||
"collaborative": collaborative,
|
||||
"parent": {
|
||||
"pk": parent_pksk,
|
||||
"sk": parent_pksk
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue