aboutsummaryrefslogtreecommitdiff
path: root/foray/Fetchers
diff options
context:
space:
mode:
Diffstat (limited to 'foray/Fetchers')
-rw-r--r--foray/Fetchers/ForayFetcher.swift14
1 files changed, 8 insertions, 6 deletions
diff --git a/foray/Fetchers/ForayFetcher.swift b/foray/Fetchers/ForayFetcher.swift
index e4c6fd9..15db4c1 100644
--- a/foray/Fetchers/ForayFetcher.swift
+++ b/foray/Fetchers/ForayFetcher.swift
@@ -21,20 +21,22 @@ class ForayFetcher {
let dateFormat = DateFormatter()
dateFormat.dateFormat = "yyyy-MM-dd"
-
+
+ // OK to throw as I believe it just errors out the decode; it isn't what we expected schema wise
return dateFormat.date(from: dateStr)!
})
return jd
}()
- func fetch<T: Decodable>(url: String) async throws -> T {
- var request = URLRequest(url: URL(string: url)!)
+ func fetch<T: Decodable>(url: URL) async throws -> T {
+ var request = URLRequest(url: url)
request.cachePolicy = .reloadRevalidatingCacheData // Needed otherwise default caching policy seems not to check properly
// Basic auth if required
- if (self.basicUsername != nil && self.basicPassword != nil) {
- let authData = (self.basicUsername! + ":" + self.basicPassword!).data(using: .utf8)!.base64EncodedString()
- request.addValue("Basic \(authData)", forHTTPHeaderField: "Authorization")
+ if let basicUsername = basicUsername,
+ let basicPassword = basicPassword,
+ let authData = (basicUsername + ":" + basicPassword).data(using: .utf8) {
+ request.addValue("Basic \(authData.base64EncodedString())", forHTTPHeaderField: "Authorization")
}
let (data, _) = try await URLSession.shared.data(for: request)