crickets-and-comb / crickets-and-comb/comb_utils

Replace `api_callers` `_set_url` and `_set_request_call` methods with members.

Open
#38 1 comment 0 reactions 0 assignees View on GitHub
enhancement help wanted
Dominant language
Python
Stars
1
Forks
3
PR merge metrics
No merged PRs in 30d

Description

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. https://github.com/crickets-and-comb/bfb_delivery/issues/138

Contributor guide

Open the contributing guide

Research direction

Start in the comb_utils.api_callers classes and trace how _set_url and _set_request_call currently configure callers. Update the API so URLs are passed during initialization and request methods are class members, then update bfb_delivery as requested in issue 138; done means callers can be used directly without unnecessary subclasses or Base* names.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
api, backend-api-design
Issue type
Refactor
Difficulty
4/5
Estimated time
3-5 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.