diff --git a/TINetworking/Sources/Mapping/BodyContent/ApplicationJsonBodyContent.swift b/TINetworking/Sources/Mapping/BodyContent/ApplicationJsonBodyContent.swift index f517c503..a99145eb 100644 --- a/TINetworking/Sources/Mapping/BodyContent/ApplicationJsonBodyContent.swift +++ b/TINetworking/Sources/Mapping/BodyContent/ApplicationJsonBodyContent.swift @@ -42,6 +42,8 @@ open class ApplicationJsonBodyContent: BaseContent, BodyContent { super.init(mediaTypeName: CommonMediaTypes.applicationJson.rawValue) } + // MARK: - BodyContent + public func encodeBody() throws -> Data { try encodingClosure() } diff --git a/TINetworking/Sources/Mapping/BodyContent/EmptyBodyContent.swift b/TINetworking/Sources/Mapping/BodyContent/EmptyBodyContent.swift index 23b5593e..faed4a9c 100644 --- a/TINetworking/Sources/Mapping/BodyContent/EmptyBodyContent.swift +++ b/TINetworking/Sources/Mapping/BodyContent/EmptyBodyContent.swift @@ -23,6 +23,9 @@ import Foundation public final class EmptyBodyContent: BaseContent, BodyContent { + + // MARK: - BodyContent + public func encodeBody() throws -> Data { Data() } diff --git a/TINetworking/Sources/Mapping/ResponseContent/ApplicationJsonResponseContent.swift b/TINetworking/Sources/Mapping/ResponseContent/ApplicationJsonResponseContent.swift index be01234a..37a6497f 100644 --- a/TINetworking/Sources/Mapping/ResponseContent/ApplicationJsonResponseContent.swift +++ b/TINetworking/Sources/Mapping/ResponseContent/ApplicationJsonResponseContent.swift @@ -31,6 +31,8 @@ open class ApplicationJsonResponseContent: BaseContent, Respon super.init(mediaTypeName: CommonMediaTypes.applicationJson.rawValue) } + // MARK: - ResponseContent + public func decodeResponse(data: Data) throws -> Model { try jsonDecoder.decode(Model.self, from: data) } diff --git a/TINetworking/Sources/Mapping/ResponseContent/MapResponseContent.swift b/TINetworking/Sources/Mapping/ResponseContent/MapResponseContent.swift index f61b983e..7e38fabb 100644 --- a/TINetworking/Sources/Mapping/ResponseContent/MapResponseContent.swift +++ b/TINetworking/Sources/Mapping/ResponseContent/MapResponseContent.swift @@ -23,18 +23,19 @@ import Foundation import TISwiftUtils -public struct MapResponseContent: ResponseContent { +public final class MapResponseContent: BaseContent, ResponseContent { private let decodeClosure: ThrowableClosure - public let mediaTypeName: String - public init(responseContent: C, transform: @escaping Closure) { - mediaTypeName = responseContent.mediaTypeName decodeClosure = { transform(try responseContent.decodeResponse(data: $0)) } + + super.init(mediaTypeName: responseContent.mediaTypeName) } + // MARK: - ResponseContent + public func decodeResponse(data: Data) throws -> Model { try decodeClosure(data) } diff --git a/TINetworking/Sources/Mapping/ResponseContent/TextPlainResponseContent.swift b/TINetworking/Sources/Mapping/ResponseContent/TextPlainResponseContent.swift index 16146104..c26cd2ff 100644 --- a/TINetworking/Sources/Mapping/ResponseContent/TextPlainResponseContent.swift +++ b/TINetworking/Sources/Mapping/ResponseContent/TextPlainResponseContent.swift @@ -22,20 +22,18 @@ import Foundation -public struct TextPlainResponseContent: ResponseContent { - struct StringDecodingError: Error { +public final class TextPlainResponseContent: BaseContent, ResponseContent { + public struct StringDecodingError: Error { let data: Data let encoding: String.Encoding } private let encoding: String.Encoding - // MARK: - Content - - public let mediaTypeName = CommonMediaTypes.textPlain.rawValue - public init(encoding: String.Encoding = .utf8) { self.encoding = encoding + + super.init(mediaTypeName: CommonMediaTypes.textPlain.rawValue) } // MARK: - ResponseContent diff --git a/TINetworking/Sources/Parameters/Encoding/PathParameterEncoding.swift b/TINetworking/Sources/Parameters/Encoding/PathParameterEncoding.swift index 4bd1148c..f11c3da5 100644 --- a/TINetworking/Sources/Parameters/Encoding/PathParameterEncoding.swift +++ b/TINetworking/Sources/Parameters/Encoding/PathParameterEncoding.swift @@ -27,6 +27,8 @@ open class PathParameterEncoding: BaseUrlParameterEncoding, ParameterEncoding { self.templateUrl = templateUrl } + // MARK: - ParameterEncoding + open func encode(parameters: [String: Parameter]) -> String { .render(template: templateUrl, using: encode(parameters: parameters)) } diff --git a/TINetworking/Sources/Parameters/Encoding/QueryStringParameterEncoding.swift b/TINetworking/Sources/Parameters/Encoding/QueryStringParameterEncoding.swift index 8b7353ff..7931e26c 100644 --- a/TINetworking/Sources/Parameters/Encoding/QueryStringParameterEncoding.swift +++ b/TINetworking/Sources/Parameters/Encoding/QueryStringParameterEncoding.swift @@ -21,6 +21,9 @@ // open class QueryStringParameterEncoding: BaseUrlParameterEncoding, ParameterEncoding { + + // MARK: - ParameterEncoding + open func encode(parameters: [String: Parameter]) -> [String: Any] { let includedKeys = Set(super.encode(parameters: parameters).map { $0.key }) diff --git a/TINetworking/Sources/Parameters/ParameterEncoding.swift b/TINetworking/Sources/Parameters/ParameterEncoding.swift index 2cc471c2..16f69eba 100644 --- a/TINetworking/Sources/Parameters/ParameterEncoding.swift +++ b/TINetworking/Sources/Parameters/ParameterEncoding.swift @@ -25,4 +25,4 @@ protocol ParameterEncoding { associatedtype Result func encode(parameters: [String: Parameter]) -> Result -} \ No newline at end of file +}