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

[feat] Add ability to construct Options object from dictionary #547

Merged
merged 2 commits into from
Feb 13, 2024

Conversation

nwithan8
Copy link
Member

Description

The Options object has always been in a weird middle-ground since we introduced parameter objects over a year ago, mainly because it it one of the few object classes in the library that is used in both requests (parameter sets) and responses (property of a Shipment model). Because the object is so large, with several dozen different "properties" (options), we've chosen not to duplicate it into request-specific and response-specific classes, but simply use the existing Options class, designed primarily for response JSON serialization, also for request JSON deserialization in parameter sets.

That has made the Options class difficult to transition to the parameter set construction paradigm we've established, especially because of how many properties it has that can be set.

This PR offers a "shortcut" to allow end-users to use a dictionary (for those still using the legacy dictionary method instead of parameter sets) to generate an Options object via a behind-the-scenes deserialization-serialization process. As with all our legacy dictionary-based functionality, this method relies on the end-user to properly construct a dictionary with the valid schema and key-value pairs (any invalid key-value pairs are inherently ignored and therefore won't produce the anticipated Options object upon de/serialization).

This is potentially the start of a larger effort to offer FromDictionary methods for all the Parameter classes to better facility (and validate) those still using the legacy dictionary workflow. For now, the Options object, due to its double-duty usage and its size and complexity, is the perfect initial candidate for this concept.

Testing

  • Added unit test to confirm new FromDictionary method works as expected

Pull Request Type

Please select the option(s) that are relevant to this PR.

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)
  • Breaking change (fix or feature that would cause existing functionality to not work as expected)
  • Improvement (fixing a typo, updating readme, renaming a variable name, etc)

@nwithan8 nwithan8 requested a review from a team as a code owner February 13, 2024 22:39
@HottieHotton
Copy link

Adding this will definitely help customers and Support who utilize the .NET library as this will allow flexibility for building scripts to help:

  1. Test customer shipments to see what the issue is on their requests
  2. Users who have integrated our API via this library condense their code so it can flexible for many options that we support here at EasyPost

@nwithan8 nwithan8 merged commit 2f9c8a5 into master Feb 13, 2024
14 checks passed
@nwithan8 nwithan8 deleted the options_from_dictionary branch February 13, 2024 23:50
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.

None yet

4 participants