OfferingsManager/OfferingsFactory: using OfferingsResponse#1435
Merged
Conversation
Merged
10 tasks
63cbf52 to
4e0dfa8
Compare
8ec75cd to
c6c0680
Compare
4e0dfa8 to
c53e94b
Compare
c6c0680 to
957cb7b
Compare
c53e94b to
7bfbd17
Compare
957cb7b to
8d75181
Compare
NachoSoto
commented
Apr 1, 2022
| let request = HTTPRequest(method: .get, path: .getOfferings(appUserID: appUserID)) | ||
|
|
||
| httpClient.perform(request, authHeaders: self.authHeaders) { (response: HTTPResponse<[String: Any]>.Result) in | ||
| httpClient.perform(request, authHeaders: self.authHeaders) { (response: HTTPResponse<OfferingsResponse>.Result) in |
Contributor
Author
There was a problem hiding this comment.
This is all it takes to get HTTPClient to deserialize the response 🤓
0e34e67 to
87a2c90
Compare
NachoSoto
added a commit
that referenced
this pull request
Apr 5, 2022
This will become the response type used everywhere by `OfferingsManager` in #1435.
8d75181 to
743c458
Compare
87a2c90 to
27a3ea3
Compare
743c458 to
8430670
Compare
a6e6d43 to
826abb8
Compare
8430670 to
921d8a8
Compare
4a6ba22 to
7445957
Compare
921d8a8 to
da91c0c
Compare
7445957 to
8e0c0be
Compare
ad774e8 to
7456ec6
Compare
OfferingsResponse in OfferingsManagerOfferingsManager/OfferingsFactory: using OfferingsResponse
Contributor
Author
|
This is finished now 🎉 |
NachoSoto
commented
Apr 11, 2022
| @@ -17,66 +17,66 @@ import StoreKit | |||
|
|
|||
| class OfferingsFactory { | |||
Contributor
Author
There was a problem hiding this comment.
No more magic strings in this file 😄
NachoSoto
commented
Apr 11, 2022
| } | ||
|
|
||
| func offerings(appUserID: String, completion: ((Offerings?, Error?) -> Void)?) { | ||
| func offerings(appUserID: String, completion: ((Result<Offerings, Error>) -> Void)?) { |
Contributor
Author
There was a problem hiding this comment.
Finished using Result around OfferingsManager too.
NachoSoto
commented
Apr 11, 2022
| } | ||
|
|
||
| func extractProductIdentifiers(fromOfferingsData offeringsData: [String: Any]) -> Set<String> { | ||
| // Fixme: parse Data directly instead of converting from Data to Dictionary back to Data |
NachoSoto
commented
Apr 11, 2022
Comment on lines
-87
to
-93
| expect(offeringA["identifier"] as? String) == "offering_a" | ||
| expect(offeringA["description"] as? String) == "This is the base offering" | ||
| expect(packageA["identifier"]) == "$rc_monthly" | ||
| expect(packageA["platform_product_identifier"]) == "monthly_freetrial" | ||
| expect(packageB["identifier"]) == "$rc_annual" | ||
| expect(packageB["platform_product_identifier"]) == "annual_freetrial" | ||
| expect(result?.value?["current_offering_id"] as? String) == "offering_a" |
Contributor
Author
There was a problem hiding this comment.
No more magic strings
NachoSoto
commented
Apr 11, 2022
| @@ -202,11 +199,15 @@ class OfferingsTests: XCTestCase { | |||
| } | |||
|
|
|||
| func testOfferingsIsNilIfNoOfferingCanBeCreated() throws { | |||
Contributor
Author
There was a problem hiding this comment.
This is kind of an end-to-end test including deserialization too.
7456ec6 to
62eaa0e
Compare
62eaa0e to
88eb5be
Compare
NachoSoto
added a commit
that referenced
this pull request
Apr 12, 2022
…rkError` and `BackendError` (#1425) Closes #695 and finishes [CF-195]. Depends on ~~#1431, #1432, #1433, #1437~~. ## Goals: - [x] Handle all requests / response / deserialization errors in `HTTPClient`. Clients of `HTTPClient` will only have to handle the "happy" path: #1431 - [x] `HTTPClient` shouldn't return `Result.success` with failed responses, forcing clients to verify the response is actually a failure: #1431 - [x] Abstract error response deserialization / error creation: #1427 - [x] Abstract attribute error parsing: #1427 - [x] Move response deserialization to `HTTPClient` based on a `ResponseType: Decodable` type, so the completion block will simply return a `Result<HTTPResponse<ResponseType>, Error>` - [x] `ETagManager` should store response `Data` instead of a deserialized `[String: Any]` - [x] Improved error types in `HTTPClient` to fix tests: #1437 - [x] Dealt with non-backwards compatible `ETagManager: #1438 ## Changes: - Replaced `HTTPResponse`'s body from `[String: Any]` to a generic `HTTPResponseBody`. - Created `HTTPResponseBody` to abstract `Decodable` and provide some default implementations for types like `Data,` `[String: Any]` (for backwards compatibility to types that aren't `Decodable` yet), and `Decodable` itself. - New `HTTPResponse.Result` typealias (`Result<HTTPResponse<HTTPResponseBody>, Error>`) used everywhere. This will allow replacing `Error` with a more specific `Error` so we can forward known typed errors, and make sure that we don't end up with the wrong error type, or with a very complex error hierarchy and the details buried in `underlyingError`. - Each layer (only a few for now) has its own error type: `NetworkError`, `BackendError`, `OfferingsManager.Error`. - `HTTPClient` for example has to produce `NetworkError`, operations produce `BackendError` - The parent `BackendError` can have specific errors like `.missingAppUserID`, but also be simply a child error `case networkError(NetworkError)` - All of these conform to a `ErrorCodeConvertible`, so there is a single point of code that converts from simple and readable errors (like `BackendError.emptySubscriberAttributes`, `.unexpectedBackendResponse(.loginResponseDecoding)`) into errors with all the context using `ErrorUtils` - Converted `DNSError` into `NetworkError.dnsError`. Its functionality remains unchanged. - Removed `Backend.RCSuccessfullySyncedKey` and `ErrorDetails.finishableKey` in favor of tested properties on `NetworkError` ### Leftovers There's a few things I've decided to not finish for now: - [ ] `CustomerInfo` still does't conform to `Decodable` (manual deserialization is still supported by the current system): #1496 - `SubscriberAttributeDict` could also be `Codable` - [x] Replace `OfferingsFactory` with `Decodable`: #1435 [CF-195]: https://revenuecats.atlassian.net/browse/CF-195?atlOrigin=eyJpIjoiNWRkNTljNzYxNjVmNDY3MDlhMDU5Y2ZhYzA5YTRkZjUiLCJwIjoiZ2l0aHViLWNvbS1KU1cifQ
97fb1d0 to
80e56be
Compare
Contributor
Author
|
This is still waiting for review 🤓 |
80e56be to
1af39a9
Compare
This takes full advantage of `Decodable` when decoding and creating `Offerings`.
1af39a9 to
7aafc8f
Compare
aboedo
approved these changes
Apr 22, 2022
Comment on lines
-87
to
-93
| expect(offeringA["identifier"] as? String) == "offering_a" | ||
| expect(offeringA["description"] as? String) == "This is the base offering" | ||
| expect(packageA["identifier"]) == "$rc_monthly" | ||
| expect(packageA["platform_product_identifier"]) == "monthly_freetrial" | ||
| expect(packageB["identifier"]) == "$rc_annual" | ||
| expect(packageB["platform_product_identifier"]) == "annual_freetrial" | ||
| expect(result?.value?["current_offering_id"] as? String) == "offering_a" |
Comment on lines
+18
to
+38
| struct OfferingsResponse { | ||
|
|
||
| struct Offering { | ||
|
|
||
| struct Package { | ||
|
|
||
| let identifier: String | ||
| let platformProductIdentifier: String | ||
|
|
||
| } | ||
|
|
||
| let identifier: String | ||
| let description: String | ||
| let packages: [Package] | ||
|
|
||
| } | ||
|
|
||
| let currentOfferingId: String? | ||
| let offerings: [Offering] | ||
|
|
||
| } |
3 tasks
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Depends on #1437.
This takes full advantage of
Decodablewhen decoding and creatingOfferings.