Skip to content

Commit

Permalink
fix: Avoid type confusion
Browse files Browse the repository at this point in the history
  • Loading branch information
PhilippeWeidmann committed Jan 30, 2025
1 parent 4ab178e commit 8c69cbe
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 8 deletions.
11 changes: 4 additions & 7 deletions Sources/InfomaniakCore/Networking/AbstractNetworkRequest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,9 @@
import Alamofire
import Foundation

/// Wrapping HTTP POST and GET parameters in this type
public typealias Parameters = [String: any Encodable & Sendable]

/// Wrapping the body of an HTTP Request with common types
public enum RequestBody {
case POSTParameters(Parameters)
case POSTParameters(EncodableParameters)
case requestBody(Data)
}

Expand All @@ -34,7 +31,7 @@ public protocol Requestable {

var route: Endpoint { get set }

var GETParameters: Parameters? { get set }
var GETParameters: EncodableParameters? { get set }

var body: RequestBody? { get set }
}
Expand Down Expand Up @@ -75,7 +72,7 @@ struct BodyDataEncoding: ParameterEncoding {
}

public struct Request: Requestable {
public init(method: Method, route: InfomaniakCore.Endpoint, GETParameters: Parameters?, body: RequestBody?) {
public init(method: Method, route: InfomaniakCore.Endpoint, GETParameters: EncodableParameters?, body: RequestBody?) {
self.method = method
self.route = route
self.GETParameters = GETParameters
Expand All @@ -86,7 +83,7 @@ public struct Request: Requestable {

public var route: InfomaniakCore.Endpoint

public var GETParameters: Parameters?
public var GETParameters: EncodableParameters?

public var body: RequestBody?
}
Expand Down
4 changes: 3 additions & 1 deletion Sources/InfomaniakCore/Networking/ApiFetcher.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,8 @@ import InfomaniakDI
import InfomaniakLogin
import Sentry

public typealias EncodableParameters = [String: any Encodable & Sendable]

public protocol RefreshTokenDelegate: AnyObject {
func didUpdateToken(newToken: ApiToken, oldToken: ApiToken)
func didFailRefreshToken(_ token: ApiToken)
Expand Down Expand Up @@ -135,7 +137,7 @@ open class ApiFetcher {

public func authenticatedRequest(_ endpoint: Endpoint,
method: HTTPMethod = .get,
parameters: [String: Encodable]? = nil,
parameters: EncodableParameters? = nil,
overrideEncoder: ParameterEncoder? = nil,
headers: HTTPHeaders? = nil,
requestModifier: RequestModifier? = nil) -> DataRequest {
Expand Down

0 comments on commit 8c69cbe

Please sign in to comment.