-
Notifications
You must be signed in to change notification settings - Fork 37
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
Authv2 / Networking improvements #1168
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # Package.swift
import Foundation | ||
import Common | ||
|
||
extension Dictionary where Key == String, Value == String { |
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.
can we make it a Collection
extension defaulting to KeyValuePairs<String, String>
– this will preserve items order
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.
Good suggestion thanks, I agree that maintaining the order is a nice to have, I tried to change it in
public typealias QueryItems = any Collection<KeyValuePairs<String, String>>
But that introduces a lot of issues (like can't access values directly by key), then I decided to stuck with
public typealias QueryItem = Dictionary<String, String>.Element
public typealias QueryItems = Array<QueryItem>
Less elegant but achieves the objective of having a data structure of ordered key value pairs
I moved everything to QueryItems.swift
@@ -107,7 +107,9 @@ struct APIClient { | |||
let url = environment.url(for: requestType) | |||
let timeout = environment.timeout(for: requestType) ?? requestConfig.defaultTimeout ?? 60 | |||
|
|||
let apiRequest = APIRequestV2(url: url, method: .get, headers: headers, timeoutInterval: timeout) | |||
guard let apiRequest = APIRequestV2(url: url, method: .get, headers: headers, timeoutInterval: timeout) else { | |||
throw APIRequestV2.Error.invalidDataType |
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 think it should crash in case we can‘t form a request as it would indicate a critical code flaw. Or at least assert if there are valid cases when a request cannot be created from a url (which I believe there‘s no).
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 it isn't realistically possible to create a invalid request via an invalid URL, but... URLComponents.init result is optional so I'm not keen to force unwrap anything. I haven't yet discovered a way to make URLComponents.init fail but I can't demonstrate that doesn't exist.
I've added an assert, but crashing in production is not an option.
} | ||
} | ||
|
||
public typealias DecodableHelper = CodableHelper |
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.
Expanded the previous DecodableHelper into CodableHelper withe helpers for encoding and decoding.
This typealias help avoid merge conflicts
|
||
import Foundation | ||
|
||
/// A convenience enum to unify the logic for selecting the right keychain through the query attributes. |
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 moved this from mac
Task/Issue URL: https://app.asana.com/0/1205842942115003/1209170372758735/f
iOS PR: duckduckgo/iOS#3820
macOS PR: duckduckgo/macos-browser#3746
What kind of version bump will this require?: Major (APIRequestV2 init can now return nil, TestUtils library has been replaced)
CC: @miasma13
Description:
Networking v2 Improvements
NetworkingTestingUtils
Additional changes include:
DecodableHelper
expanded and renamedCodableHelper
Date
extension with utilities + unit testsXYZTestingUtils
module, I removed the genericTestingUtils
Steps to test this PR:
Internal references:
Software Engineering Expectations
Technical Design Template