Skip to content

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 <31996+avelino@users.noreply.github.com>
Copy link

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":

Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
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 <31996+avelino@users.noreply.github.com>
Added tests for all BarteClient class methods,
ensuring complete code coverage.

Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
- 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 <31996+avelino@users.noreply.github.com>
Signed-off-by: Avelino <31996+avelino@users.noreply.github.com>
@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 <31996+avelino@users.noreply.github.com>
* 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.

4 participants