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

Support Encodable POST types #1151

Merged
merged 15 commits into from
Dec 11, 2023
Merged

Support Encodable POST types #1151

merged 15 commits into from
Dec 11, 2023

Conversation

scannillo
Copy link
Contributor

Why

  • Setting the stage for moving our JSON modeling away from raw Swift dictionaries and to Encodable types
  • Benefits
    • Singular .swift files to house POST formatting
    • Swift best practice
    • More performant than raw dictionary encoding (want to use Xcode's Time Profiler/Signposts in the future to measure)

Summary of changes

  • Apple Pay example. Used to test changes & set example for other features to make this change.
    • Add BTApplePaymentTokensRequest encodable type
  • Add BTAPIClient.post(parameters: Encodable, ...)
  • Add BTAPIRequest struct which represents the final end-state of the POST body for GW & GraphQL API requests
  • Conform BTClientMetadata to Encodable

Checklist

  • Added a changelog entry

Authors

@scannillo

@scannillo scannillo marked this pull request as ready for review December 8, 2023 18:38
@scannillo scannillo requested a review from a team as a code owner December 8, 2023 18:38

var metadataContainer = encoder.container(keyedBy: MetadataKeys.self)
if httpType == .gateway {
let metadataEncoder = metadataContainer.superEncoder(forKey: .gatewayMetadataKey)
Copy link
Contributor

Choose a reason for hiding this comment

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

TIL about superEncoder - super cool!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yeh, it was a little tricky to figure out how to do this, but this stack overflow post is what helped me - https://stackoverflow.com/questions/50461744/swift-codable-how-to-encode-top-level-data-into-nested-container

Sources/BraintreeCore/BTAPIRequest.swift Outdated Show resolved Hide resolved
@scannillo
Copy link
Contributor Author

UI test failures unrelated

@scannillo scannillo merged commit 463bf7d into main Dec 11, 2023
5 of 6 checks passed
@scannillo scannillo deleted the use-codable-api-client branch December 11, 2023 18:05
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.

3 participants