diff --git a/Sources/CumulocityCoreLibrary/Supplementary/AdaptableApi.swift b/Sources/CumulocityCoreLibrary/Supplementary/AdaptableApi.swift index adc7600..8291c43 100644 --- a/Sources/CumulocityCoreLibrary/Supplementary/AdaptableApi.swift +++ b/Sources/CumulocityCoreLibrary/Supplementary/AdaptableApi.swift @@ -13,7 +13,7 @@ public class AdaptableApi { let requestBuilder: URLRequestBuilder let session: URLSession - public init(requestBuilder: URLRequestBuilder = URLRequestBuilder(), withSession session: URLSession = URLSession.shared) { + public init(requestBuilder: URLRequestBuilder = URLRequestBuilder(), withSession session: URLSession = Cumulocity.Core.shared.session) { self.requestBuilder = requestBuilder self.session = session } diff --git a/Sources/CumulocityCoreLibrary/Supplementary/URLRequestBuilder.swift b/Sources/CumulocityCoreLibrary/Supplementary/URLRequestBuilder.swift index e2df668..20c7c63 100644 --- a/Sources/CumulocityCoreLibrary/Supplementary/URLRequestBuilder.swift +++ b/Sources/CumulocityCoreLibrary/Supplementary/URLRequestBuilder.swift @@ -34,27 +34,32 @@ public class URLRequestBuilder { self.queryItems = with.queryItems } + @discardableResult public func set(scheme: String) -> URLRequestBuilder { self.components.scheme = scheme return self } + @discardableResult public func set(host: String) -> URLRequestBuilder { self.components.host = host return self } + @discardableResult public func set(resourcePath: String) -> URLRequestBuilder { self.components.path = resourcePath return self } + @discardableResult public func set(httpMethod: String) -> URLRequestBuilder { self.httpMethod = httpMethod return self } - public func add(header: String, value: Subject?) -> URLRequestBuilder { + @discardableResult + public func add(header: String, value: Subject?) -> URLRequestBuilder { if let v = value { let valueAsString = String(describing: v) guard !valueAsString.isEmpty else { @@ -65,8 +70,9 @@ public class URLRequestBuilder { return self } - public func set(authorization userName: String, password: String) -> URLRequestBuilder { - let credentials = "\(userName):\(password)" + @discardableResult + public func set(authorization userName: String, password: String) -> URLRequestBuilder { + let credentials = "\(userName):\(password)" if let encodedCredentials = credentials.data(using: .utf8) { self.requestHeaders["Authorization"] = "Basic " + encodedCredentials.base64EncodedString() } @@ -76,7 +82,8 @@ public class URLRequestBuilder { /// Appends a ``URLQueryItem`` based on the passed ``key``/``value`` pair if ``value`` is not nil. /// /// The parameter will be serialized as `?key=value`. - public func add(queryItem key: String, value: Subject?) -> URLRequestBuilder { + @discardableResult + public func add(queryItem key: String, value: Subject?) -> URLRequestBuilder { if let v = value { let valueAsString = String(describing: v) guard !valueAsString.isEmpty else { @@ -92,6 +99,7 @@ public class URLRequestBuilder { /// The parameter `explode` defines the serialisation method: /// - If `true`, parameter will be serialized as `?key=1&key=2&key=3`. /// - If `false`, parameter will be serialized as `?key=1,2,3`. + @discardableResult public func add(queryItem key: String, value: [Subject]?, explode: ParameterSerializationType = .exploded) -> URLRequestBuilder { if let v = value { if explode == .exploded { @@ -105,7 +113,8 @@ public class URLRequestBuilder { return self } - public func set(httpBody: Data?) -> URLRequestBuilder { + @discardableResult + public func set(httpBody: Data?) -> URLRequestBuilder { self.httpBody = httpBody return self }