easypost-php icon indicating copy to clipboard operation
easypost-php copied to clipboard

feat: thread safety via new EasyPostClient object

Open Justintime50 opened this issue 2 years ago • 1 comments

Description

Uses new EasyPostClient object which provides thread-safety. All functions are now called against a client object ensuring that API keys cannot get mixed via the global state. Syntax now looks like $client->address->create();. Various files were moved to provide better project structure, a few functions were shuffled, lots of code was removed as it was no longer necessary with the architecture changes here. Code that has not been confirmed dead yet was retained for now (can revisit and remove later, most of it lives in EasyPostObject).

Testing

  • All the tests were updated to reflect the new syntax
  • Tested autocomplete does indeed work (won't work inside our test suite but did with a scratch file)
  • The require test did a great job of reminding me to catch all the new imports needed

Pull Request Type

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

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

Justintime50 avatar Dec 06 '22 21:12 Justintime50

Can we group all the models (Shipment.php, Rate.php, etc.) into a "Model" folder?

Unfortunately not without undesirable consequences. In PHP, the folder is important to the namespace and we don't want root level "EasyPost" objects to be nestled in some "Model" folder, asserting they are a type of Address would no longer be \EasyPost\Address it would be an awkward EasyPost\Model\Address. If you look at Stripe's PHP lib, they've done the same actually. I've pulled everything that isn't a "Model" into a separate namespace/folder to try and keep them consistent that way.

Justintime50 avatar Dec 09 '22 23:12 Justintime50