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

refactor: change to complex objects instead of raw dictionaries #1

Merged
merged 11 commits into from
Jan 9, 2025

Conversation

avelino
Copy link
Member

@avelino avelino commented Jan 8, 2025

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.

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]>
Copy link

@Copilot Copilot AI left a 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 in Charge class modifies the input data 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 in PixCharge class directly modifies the instance attributes. Return a new instance with the updated attributes to maintain immutability.
def get_qr_code(self) -> "PixCharge":

barte/models.py Outdated Show resolved Hide resolved
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]>
barte/models.py Outdated Show resolved Hide resolved
barte/models.py Outdated Show resolved Hide resolved
- 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]>
@avelino avelino requested a review from ecarrara January 8, 2025 20:49
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]>
* 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
@avelino avelino merged commit 81f6d74 into main Jan 9, 2025
5 checks passed
@avelino avelino deleted the avelino/change-to-complex-obj branch January 9, 2025 14:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants