Skip to content

Replace api_callers _set_url and _set_request_call methods with members. #38

@KalebCoberly

Description

@KalebCoberly

We currently use helper methods in the base api_callers classes to set the API URL to call and the request method to call (e.g., get, post, etc.). This works fine, but makes for a clunky way to use the classes, requiring extension instead of just using the classes out of the box.

It would be better if the API URL and the request method were simply class members that could be set upon initialization and class definition, respectively.

For instance, to use BaseGetCaller , you currently need to extend the class into a new class:

    from comb_utils.api_callers import BaseGetCaller

    class MyAPICaller(BaseGetCaller):

        def _set_url(self):
            self.url = "https://api.example.com/data"

    my_caller = MyCaller()
    my_caller.call_api()
    target_response_value = my_caller.target_response_value

BaseGetCaller itself extends BaseCaller by overriding the _set_request_call method.

If we rewrote BaseCaller to accept the URL in __init__, users could use BaseGetCaller directly without having to create a new child class:

from comb_utils.api_callers import BaseGetCaller

my_caller = BaseGetCaller(url="https://api.example.com/data")
my_caller.call_api()
target_response_value = my_caller.target_response_value

And, if we rewrote BaseCaller to no longer have a _set_request_caller method, we could just set the _request_caller member at class definition for BaseGetCaller and other child classes:

import requests

class BaseGetCaller(BaseAPICaller):

    request_caller = requests.get
    ...

Additionally, allowing users to simply pass the URL at initialization and thus use our base callers off the shelf, would allow use to drop the "Base*" naming convention (except for BaseCaller itself, which still would need to be extended). So, BaseGetCaller could be renamed to something like GetCaller etc.

You'll need to update bfb_delivery to use this. crickets-and-comb/bfb_delivery#138

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or requesthelp wantedExtra attention is needed

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions