-
Notifications
You must be signed in to change notification settings - Fork 59
clean up address verify property and some miscellaneous request logic #127
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
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
83 changes: 83 additions & 0 deletions
83
tests/cassettes/test_address_creation_with_verify_bool.yaml
This file contains hidden or 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,83 @@ | ||
| interactions: | ||
| - request: | ||
| body: address%5Bcity%5D=San+Francisco&address%5Bcompany%5D=EasyPost&address%5Bcountry%5D=US&address%5Bphone%5D=415-456-7890&address%5Bstate%5D=CA&address%5Bstreet1%5D=118+2&address%5Bstreet2%5D=FLoor+4&address%5Bzip%5D=94105 | ||
| headers: | ||
| Accept: | ||
| - '*/*' | ||
| Accept-Encoding: | ||
| - gzip, deflate | ||
| Connection: | ||
| - keep-alive | ||
| Content-Length: | ||
| - '218' | ||
| Content-type: | ||
| - application/x-www-form-urlencoded | ||
| authorization: | ||
| - EZTK-NONE | ||
| user-agent: | ||
| - easypost/v2 pythonclient/suppressed | ||
| x-client-user-agent: | ||
| - suppressed | ||
| method: POST | ||
| uri: https://api.easypost.com/v2/addresses?verify%5B%5D=true | ||
| response: | ||
| body: | ||
| string: !!binary | | ||
| H4sIAAAAAAAAA4ySzU7jMBSFXyXylhRsN2nS7KIySCOhgkhZjEYocuwbxiPHrmwHARXvznULs5hV | ||
| s3Hu8Xeuj38ORCvSEKF8v+IDH0ZVg2R1IYWoGZMg1uuCVeuqHgaSEzf8BRmRb5XyEAJK0oOIoHqR | ||
| ZE45W9DVgrId503JG0YvKG0oRXDeq/NAKyYgjZ2Nwe5u2gv7ho4fbffr/q7bIRCiB4gMRcbqjG+v | ||
| s26X3dxmxb85jnMpm47J2rXb7Oah3W5+dpu7I4NBUN+0WLzrPf7iJmm5WK54CiDdbKNPzscOy/0f | ||
| ZxNesLIoV1W9TgxMQpvvlJNTCYgQYrIL7zX4fhRSm2OCE4UHphXYqAUaR2EC5GQEBV6YPorXPl3E | ||
| iTwG/E97Aa9HLUXUzgbSHFLwIo1hljJdRRP9jB3Be+ex+v2UEwURU4ZTi49UG4193s61HYjB9eKc | ||
| dresLqu6qsqcGGefv8QF4/xyiU+kyknUE/Tvp6NqJ0wrxdWtC31rn8FAIB/4fQIAAP//AwDow9Tp | ||
| bgIAAA== | ||
| headers: | ||
| cache-control: | ||
| - no-cache, no-store | ||
| content-encoding: | ||
| - gzip | ||
| content-type: | ||
| - application/json; charset=utf-8 | ||
| etag: | ||
| - W/"b7d8f69ebe4ba9aee3182e54d399f72a" | ||
| expires: | ||
| - '0' | ||
| location: | ||
| - /api/v2/addresses/adr_62b2bfd8ec184caa811cea99417978bb | ||
| pragma: | ||
| - no-cache | ||
| referrer-policy: | ||
| - strict-origin-when-cross-origin | ||
| strict-transport-security: | ||
| - max-age=15768000; includeSubDomains; preload | ||
| transfer-encoding: | ||
| - chunked | ||
| x-backend: | ||
| - easypost | ||
| x-content-type-options: | ||
| - nosniff | ||
| x-download-options: | ||
| - noopen | ||
| x-ep-request-uuid: | ||
| - d6502afc60b6ba1afb32a2c100f6fc6a | ||
| x-frame-options: | ||
| - SAMEORIGIN | ||
| x-node: | ||
| - bigweb5nuq | ||
| x-permitted-cross-domain-policies: | ||
| - none | ||
| x-proxied: | ||
| - intlb1nuq 15c8815ace | ||
| - extlb1nuq 15c8815ace | ||
| x-request-id: | ||
| - 1d5229af-27c8-4ffb-a2f9-b2fa88d35b9e | ||
| x-runtime: | ||
| - '0.056680' | ||
| x-version-label: | ||
| - easypost-202106012134-e838b9cad4-master | ||
| x-xss-protection: | ||
| - 1; mode=block | ||
| status: | ||
| code: 201 | ||
| message: Created | ||
| version: 1 |
This file contains hidden or 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
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.
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.
It's not clear to me why this list encoding needs its own special function, as opposed to passing the list as a parameter to
requestor.request. It looks like_urlencode_listbehaves slightly differently than the default list encoder in that it doesn't include an index inside the[], and our API docs do not indicate that an index should be included in the param name. Perhaps the other list encoder is incorrect?Uh oh!
There was an error while loading. Please reload this page.
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.
frankly I think we should just switch to encoding the bodies to JSON and get rid of all of this (absolutely awful) urlencoding crap
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.
I agree that we should eventually move away from the nasty URL encoding for URL params. I looked into it some more, and part of the challenge is that our underlying HTTP library has to support both Python Requests (the good one), and also Google App Engine's
urlfetcher(which is somewhat non-standard, and probably enforced for performance/security reasons on their cloud compute environment).The way the client library is structured now has it so that URL parameters are encoded earlier on, before we get to the part where the HTTP library is even engaged.
Python Requests has a clean interface to encode URL params that also takes care of the URL encoding issues, but we aren't taking advantage of this.
In a future iteration of this library, I'd like to see the URL encoding logic pushed as far down as possible, and maintain a Python dictionary for the URL parameters and payload throughout most of the code, and do the necessary conversions only where necessary.
I would like to see the "multiple-path handling" logic for accommodating the two different HTTP libraries eventually be implemented as two different adapters or strategies hidden behind a wrapper for cleaner abstraction.
To pass in a list of params, the two common practices are to do one of:
a)
base/url?fav_foods=pizza&fav_foods=ice_cream&fav_foods=sushiORb)
base/url?fav_foods[]=pizza&fav_foods[]=ice_cream&fav_foods[]=sushiIt's very wrong to have a list index inside the param. The former works, but various HTTP frameworks aren't implemented correctly to handle it, and the latter is also not idea, being a pattern that is used by some popular HTTP frameworks like Django and others, but again, not ubiquitous.
James's suggestion to do away with URL parameters and just encode the whole thing and pass as a JSON body is the most correct/ideal.
In Conclusion
Given all of the options (and the difficulty in implementing them right now), and that this change is correct, I am comfortable accepting and merging this code as is.
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.
I strongly agree with moving away from URL-encoding request parameters.
@jontsai putting an adapter in front of the HTTP request logic is a good idea, whether or not we stick with URL encoding parameters. In addition to that, I would love to drop support for
urlfetch, as it's not in the GAE Python 3 runtime. Sadly, however, Google has stated that they will continue to support the 2.7 runtime indefinitely, so it's not clear when we'll be able to do that.