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

Require Encodable body for all GET requests #1166

Merged
merged 5 commits into from
Jan 5, 2024
Merged

Require Encodable body for all GET requests #1166

merged 5 commits into from
Jan 5, 2024

Conversation

scannillo
Copy link
Contributor

@scannillo scannillo commented Dec 29, 2023

Summary of changes

  • Replace BTHTTP.get() method to require Encodable body instead of raw dictionary param
  • Add Request.swift files for the 2 GET requests that exist in the SDK
    • BTAmexRewardsBalanceRequest
    • BTConfigurationRequest
  • Update tests accordingly

Checklist

  • Added a changelog entry

Authors

@scannillo

@scannillo scannillo requested a review from a team as a code owner December 29, 2023 16:12
httpRequestWithCaching(method: "GET", path: path, parameters: parameters, completion: completion)
} else {
httpRequest(method: "GET", path: path, parameters: parameters, completion: completion)
func get(_ path: String, parameters: Encodable? = nil, shouldCache: Bool = false, completion: @escaping RequestCompletion) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In a future PR, we can make parameters non-optional, since there are no get() calls in the SDK that don't include this value.

Comment on lines +26 to +27
XCTAssertEqual(lastGetParameters["currencyIsoCode"] as! String, "fake-code")
XCTAssertEqual(lastGetParameters["paymentMethodNonce"] as! String, "fake-nonce")
Copy link
Contributor Author

@scannillo scannillo Dec 29, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This work has been a good exercise, since it reveals that we aren't testing the formatting of most our JSON bodies for both GET & POST requests right now 😬 (as also evidenced in #1151)

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't completely understand the example that reveals we aren't testing the formatting of JSON bodies. Maybe understanding it would give me the answer to my question.

Q: Why do we care about the formatting of the JSON as long as the key value pairs are the same?

Copy link
Contributor

@agedd agedd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this looks great! just one curious q: what would be the main benefit for using Encodable in the request body

@scannillo
Copy link
Contributor Author

this looks great! just one curious q: what would be the main benefit for using Encodable in the request body

Great question!

  1. Speed - dictionary literals can be a bottleneck to compile time (see previous PR).
  2. It is more Swifty/ best practice. Since we just converted to Swift, we can finally take advantage of Encodable & Decodable protocols. We couldn't in Objective-C.

@scannillo scannillo merged commit 8bb53f3 into main Jan 5, 2024
7 checks passed
@scannillo scannillo deleted the get-encodable branch January 5, 2024 20:48
/// The GET parameters for `v1/payment_methods/amex_rewards_balance`
struct BTAmexRewardsBalanceRequest: Encodable {

private let currencyIsoCode: String
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit for a future PR but we should update this to currencyISOCode to match our style guide preferences. Same in the init

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