refactor: fix code review notes
This commit is contained in:
parent
8397f15ec5
commit
4b818afa85
|
|
@ -42,6 +42,8 @@ open class ApplicationJsonBodyContent<Body>: BaseContent, BodyContent {
|
|||
super.init(mediaTypeName: CommonMediaTypes.applicationJson.rawValue)
|
||||
}
|
||||
|
||||
// MARK: - BodyContent
|
||||
|
||||
public func encodeBody() throws -> Data {
|
||||
try encodingClosure()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,6 +23,9 @@
|
|||
import Foundation
|
||||
|
||||
public final class EmptyBodyContent: BaseContent, BodyContent {
|
||||
|
||||
// MARK: - BodyContent
|
||||
|
||||
public func encodeBody() throws -> Data {
|
||||
Data()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -31,6 +31,8 @@ open class ApplicationJsonResponseContent<Model: Decodable>: BaseContent, Respon
|
|||
super.init(mediaTypeName: CommonMediaTypes.applicationJson.rawValue)
|
||||
}
|
||||
|
||||
// MARK: - ResponseContent
|
||||
|
||||
public func decodeResponse(data: Data) throws -> Model {
|
||||
try jsonDecoder.decode(Model.self, from: data)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -23,18 +23,19 @@
|
|||
import Foundation
|
||||
import TISwiftUtils
|
||||
|
||||
public struct MapResponseContent<Model>: ResponseContent {
|
||||
public final class MapResponseContent<Model>: BaseContent, ResponseContent {
|
||||
private let decodeClosure: ThrowableClosure<Data, Model>
|
||||
|
||||
public let mediaTypeName: String
|
||||
|
||||
public init<C: ResponseContent>(responseContent: C, transform: @escaping Closure<C.Model, Model>) {
|
||||
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)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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
|
||||
|
|
|
|||
|
|
@ -27,6 +27,8 @@ open class PathParameterEncoding: BaseUrlParameterEncoding, ParameterEncoding {
|
|||
self.templateUrl = templateUrl
|
||||
}
|
||||
|
||||
// MARK: - ParameterEncoding
|
||||
|
||||
open func encode(parameters: [String: Parameter<LocationPath>]) -> String {
|
||||
.render(template: templateUrl, using: encode(parameters: parameters))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -21,6 +21,9 @@
|
|||
//
|
||||
|
||||
open class QueryStringParameterEncoding: BaseUrlParameterEncoding, ParameterEncoding {
|
||||
|
||||
// MARK: - ParameterEncoding
|
||||
|
||||
open func encode(parameters: [String: Parameter<LocationQuery>]) -> [String: Any] {
|
||||
let includedKeys = Set(super.encode(parameters: parameters).map { $0.key })
|
||||
|
||||
|
|
|
|||
|
|
@ -25,4 +25,4 @@ protocol ParameterEncoding {
|
|||
associatedtype Result
|
||||
|
||||
func encode(parameters: [String: Parameter<Location>]) -> Result
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue