Refactoring
This commit is contained in:
parent
b3dcd06298
commit
4d21fe0577
|
|
@ -40,12 +40,12 @@ public extension Encodable {
|
|||
/// - Returns: URLQueryItems array
|
||||
func asUrlQueryItems() throws -> [URLQueryItem] {
|
||||
return try toJSON().map {
|
||||
if let value = $1 as? Encodable,
|
||||
let jsonData = try? JSONSerialization.data(withJSONObject: value.toJSON(), options: []),
|
||||
if ($1 is [String: Any] || $1 is [Any]),
|
||||
let jsonData = try? JSONSerialization.data(withJSONObject: $1, options: []),
|
||||
let jsonString = String(data: jsonData, encoding: .utf8) {
|
||||
return URLQueryItem(name: $0, value: jsonString)
|
||||
} else if let value = $1 as? CustomStringConvertible {
|
||||
return URLQueryItem(name: $0, value: "\(value)")
|
||||
return URLQueryItem(name: $0, value: value.description)
|
||||
} else {
|
||||
throw LeadKitError.failedToEncodeQueryItems
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue