Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Patch Api v1 #1

Merged
merged 25 commits into from
Feb 2, 2021
Merged

Patch Api v1 #1

merged 25 commits into from
Feb 2, 2021

Conversation

biglovisa
Copy link
Contributor

@biglovisa biglovisa commented Jan 22, 2021

What

Adding v1 of the package

Why

To make our Python using customers happy

SDK Release Checklist

  • Have you added an integration test for the changes?
  • Have you built the gem locally and made queries against it successfully?
  • Did you update the changelog?
  • Did you bump the package version?
  • For breaking changes, did you plan for the release of the new SDK versions and deploy the API to production?

Outstanding work

  • write integration tests for Preferences
  • write integration tests for Orders
  • Set up badge fury
  • Publish the package to PiPy and set up publish.yml

@biglovisa biglovisa self-assigned this Jan 22, 2021
@biglovisa biglovisa added the Needs Review The PR is ready to be reviewed label Jan 28, 2021
@biglovisa biglovisa requested a review from thdaraujo January 28, 2021 00:44
@@ -0,0 +1,5 @@
repos:
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Configuration for using the pre-commit package and black code formatter.

@@ -32,27 +32,24 @@ pip install patch

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Read through the README to get an idea of the interface!

README.md Outdated
```

The `api_client` will be used to instantiate other API objects for Patch resources, for example the `OrdersApi`:

```
import patch_api
from patch_api.api.orders_api import OrdersApi
from patch_api.api.orders_api import OrdersApi as Orders
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We talked about dropping the {Resource}Api from the API models and I tried to implement it but couldn't figure out how to do it well, so specifying to use aliased imports was a workaround to get a cleaner interface. LMK what you think.

Copy link
Contributor

@thdaraujo thdaraujo Jan 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

hmm maybe we can import these resources on __init__.py but rename them, and then expose/make them public by using __all__. 🤔
Not sure if it would work, would need some testing.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I tried doing that in code in a template in client-code-generation, but the variables weren't being evaluated properly? I can try again though, it feels like it should be possible. Worst case scenario we can have a template that we have to manually update when new API resources are being added.

README.md Outdated
configuration = patch_api.Configuration(api_key=os.environ.get('SANDBOX_API_KEY'))
api_client = patch_api.ApiClient(configuration)
orders_api = OrdersApi(api_client=api_client)
api_client = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY'))
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The api_client instance can be reused, but each resource interface instance (Orders, Estimates, etc) need to be instantiated with an api_client instance.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to pass the api_key to the api resources?
Maybe as public configuration variable?

We could do something like:

patch_api.api_key = "blah"

This could live on __init__.py.

See this example: https://github.com/stripe/stripe-python/blob/master/stripe/__init__.py

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes.... that is much better and we don't have to init/pass around api_client objects all over the place. Will look at this today!

Copy link
Contributor

@thdaraujo thdaraujo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nice job, thanks for working on this!

I left a couple of comments and suggestions, let me know what you think!

README.md Show resolved Hide resolved
Makefile Show resolved Hide resolved
git_push.sh Outdated Show resolved Hide resolved
test/test_create_preference_request.py Outdated Show resolved Hide resolved
test/test_estimates_api.py Show resolved Hide resolved
test/test_estimates_api.py Outdated Show resolved Hide resolved
test/test_meta_index_object.py Outdated Show resolved Hide resolved
test/test_projects_api.py Show resolved Hide resolved
README.md Outdated
configuration = patch_api.Configuration(api_key=os.environ.get('SANDBOX_API_KEY'))
api_client = patch_api.ApiClient(configuration)
orders_api = OrdersApi(api_client=api_client)
api_client = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY'))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a way to pass the api_key to the api resources?
Maybe as public configuration variable?

We could do something like:

patch_api.api_key = "blah"

This could live on __init__.py.

See this example: https://github.com/stripe/stripe-python/blob/master/stripe/__init__.py

README.md Outdated
from patch_api.api.orders_api import OrdersApi as Orders

api_client = patch_api.ApiClient(api_key=os.environ.get('SANDBOX_API_KEY'))
orders_api = Orders(api_client=api_client)
Copy link
Contributor

@thdaraujo thdaraujo Jan 29, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think one thing that could be done here is to implement the __getattr__ method and use it to chain the calls to the api resources. It works pretty much like ruby's method_missing.

I'm pretty sure it would allow us to do something like:

patch_api.orders.create_order(some_attrs)

By implementing __get_attr__, you could return a new instance of the requested ApiResource (in this case, OrdersApi) and pass in self.api_client or the self.api_key from the parent object.

This could make this interface a little cleaner.

Here's an example from the chargify python api: https://github.com/ipmb/chargify-python/blob/ed6e49559da53f36006800bc3355d31696b01175/chargify.py#L110

Here's an explanation of how it works: https://blog.rmotr.com/python-magic-methods-and-getattr-75cf896b3f88

Let me know if that makes sense!

Copy link
Contributor

@thdaraujo thdaraujo left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good to me, but left a few comments.

Makefile Outdated Show resolved Hide resolved
test/test_orders_api.py Outdated Show resolved Hide resolved
test/test_orders_api.py Outdated Show resolved Hide resolved
Co-authored-by: Thiago Araujo <thd.araujo@gmail.com>
@biglovisa biglovisa merged commit 160fe9e into main Feb 2, 2021
@biglovisa biglovisa deleted the lovisa/python-v1 branch February 2, 2021 18:24
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Needs Review The PR is ready to be reviewed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants