-
Notifications
You must be signed in to change notification settings - Fork 1
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
refactor: change to complex objects instead of raw dictionaries #1
Merged
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This commit introduces a significant architectural change in how we handle API responses. Instead of working with raw dictionaries, we now use proper model classes (Charge, CardToken, Refund, etc.) to represent API resources. Key changes: - Created new models.py file with proper data classes for all API resources - Updated client methods to return typed objects instead of dictionaries - Modified examples to demonstrate usage with new object-oriented approach - Updated tests to work with new model classes - Added type hints throughout the codebase This change brings several benefits: 1. Better type safety and IDE support 2. More intuitive API with proper object methods 3. Easier validation and data manipulation 4. Improved code maintainability 5. Better documentation through type hints The change is backwards compatible as the model classes can still be accessed as dictionaries through their attributes. Signed-off-by: Avelino <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Copilot reviewed 5 out of 7 changed files in this pull request and generated 1 comment.
Files not reviewed (2)
- examples/basic_usage.py: Evaluated as low risk
- tests/test_client.py: Evaluated as low risk
Comments suppressed due to low confidence (2)
barte/models.py:41
- The
from_dict
method inCharge
class modifies the inputdata
dictionary directly. Create a copy of the dictionary before modifying it.
def from_dict(cls, data: Dict[str, Any]) -> "Charge":
barte/models.py:69
- The
get_qr_code
method inPixCharge
class directly modifies the instance attributes. Return a new instance with the updated attributes to maintain immutability.
def get_qr_code(self) -> "PixCharge":
Signed-off-by: Avelino <[email protected]>
Change the response from dict to complex object, making it easier to use the SDK and having better type hints in the IDE. This change includes: - Adding PixQRCode model - Updating client to use complex objects - Updating tests to handle complex objects - Adding examples with complex objects Signed-off-by: Avelino <[email protected]>
Added tests for all BarteClient class methods, ensuring complete code coverage. Signed-off-by: Avelino <[email protected]>
ecarrara
reviewed
Jan 8, 2025
- change from_dict to dacite lib - add dacite config to handle datetime - add dacite config to handle list of installment simulation Signed-off-by: Avelino <[email protected]>
Signed-off-by: Avelino <[email protected]>
The datetime parser in DACITE_CONFIG has been updated to use python-dateutil's parse function instead of datetime.fromisoformat. This change provides more robust datetime parsing capabilities and better handles various datetime string formats. Signed-off-by: Avelino <[email protected]>
ecarrara
approved these changes
Jan 9, 2025
walison17
approved these changes
Jan 9, 2025
* main: feat: change datetime parser to use python-dateutil chore: drop support for Python 3.10 refactor: change from_dict to dacite lib feat: achieved 100% test coverage feat: change response to complex object refactor: change to complex objects instead of raw dictionaries docs: add links to API documentation and integration guide Update README.md gh action: remove codecov Update README.md
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This commit introduces a significant architectural change in how we handle API responses. Instead of working with raw dictionaries, we now use proper model classes (Charge, CardToken, Refund, etc.) to represent API resources.
Key changes:
This change brings several benefits:
The change is backwards compatible as the model classes can still be accessed as dictionaries through their attributes.