Skip to content

Commit 60cb6f6

Browse files
committed
Relase 2.4.0.
1 parent 2a8a5ed commit 60cb6f6

10 files changed

Lines changed: 121 additions & 24 deletions

File tree

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
//
2+
// Date+Core.swift
3+
// ReTodoList
4+
//
5+
// Created by Maksim Ivanov on 12.08.2022.
6+
//
7+
8+
import Foundation
9+
10+
extension Data {
11+
12+
public var asUTF8: String {
13+
String(decoding: self, as: UTF8.self)
14+
}
15+
}

Source/Logger/LoggerImpl.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,13 +28,13 @@ extension LogLevel {
2828
switch self {
2929
case .debug:
3030
return .debug
31-
31+
3232
case .info:
3333
return .default
34-
34+
3535
case .warn:
3636
return .error
37-
37+
3838
case .error:
3939
return .fault
4040
}

Source/Networking/Http.swift

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
//
2+
// Http.swift
3+
// PersonalDictionary
4+
//
5+
// Created by Maxim Ivanov on 15.07.2023.
6+
//
7+
8+
import Foundation
9+
10+
public struct Http {
11+
public let urlString: String
12+
public let method: String
13+
public let headers: [String: String]?
14+
public let body: Data?
15+
16+
public init(urlString: String = "",
17+
method: String = "GET",
18+
headers: [String: String]? = nil,
19+
body: Data? = nil) {
20+
self.urlString = urlString
21+
self.method = method
22+
self.headers = headers
23+
self.body = body
24+
}
25+
26+
func setBody(_ data: Data) -> Http {
27+
.init(urlString: urlString, method: method, headers: headers, body: data)
28+
}
29+
}

Source/Networking/HttpClient.swift

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,6 @@ import Foundation
1010

1111
public typealias RxHttpResponse = AnyPublisher<(response: HTTPURLResponse, data: Data), Error>
1212

13-
public struct Http {
14-
public let urlString: String
15-
public let method: String
16-
public let headers: [String: String]?
17-
public let body: Data?
18-
19-
public init(urlString: String = "",
20-
method: String = "GET",
21-
headers: [String: String]? = nil,
22-
body: Data? = nil) {
23-
self.urlString = urlString
24-
self.method = method
25-
self.headers = headers
26-
self.body = body
27-
}
28-
}
29-
3013
public protocol HttpClient {
3114

3215
func send(_ http: Http) -> RxHttpResponse

Source/Networking/HttpClientAdapter.swift

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,18 @@ public protocol HttpClientAdapter {
2121

2222
func send(_ http: Http) async throws -> HttpResponseResult
2323
}
24+
25+
extension HttpClientAdapter {
26+
27+
public func sendAndDecode<Output: Decodable>(_ http: Http) async throws -> Output {
28+
let httpResponse = try await send(http)
29+
30+
return try JSONDecoder().decode(Output.self, from: httpResponse.data)
31+
}
32+
33+
public func sendAndDecode<Body: Encodable, Output: Decodable>(_ http: Http, _ body: Body) async throws -> Output {
34+
let body = try JSONEncoder().encode(body)
35+
36+
return try await sendAndDecode(http.setBody(body))
37+
}
38+
}

Source/Networking/LoggableHttpClient.swift

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,14 +18,18 @@ public final class LoggableHttpClient: HttpClient {
1818
public func send(_ http: Http) -> RxHttpResponse {
1919
logger.log("HTTP REQUEST START: \(http)", level: .info)
2020

21+
if let body = http.body {
22+
logger.log("HTTP REQUEST BODY: \(body.asUTF8)", level: .info)
23+
}
24+
2125
return httpClient.send(http)
2226
.handleEvents(
2327
receiveOutput: { httpResponse in
2428
self.logger.log(
2529
"""
2630
HTTP RESPONSE FETCHED
2731
HTTPURLResponse: \(httpResponse.response)
28-
Data: \(String(decoding: httpResponse.data, as: UTF8.self))
32+
HTTP_Response_Data: \(httpResponse.data.asUTF8)
2933
""",
3034
level: .info
3135
)

Source/UIKit+Core/UIColor+Core.swift

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,8 @@ import UIKit
99

1010
public extension UIColor {
1111

12-
/// Creates a color object that generates its color data dynamically using the specified colors. For early SDKs creates light color.
12+
/// Creates a color object that generates its color data dynamically using the specified colors.
13+
/// For early SDKs creates light color.
1314
/// - Parameters:
1415
/// - light: The color for light mode.
1516
/// - dark: The color for dark mode.
@@ -21,8 +22,7 @@ public extension UIColor {
2122
}
2223
return light
2324
}
24-
}
25-
else {
25+
} else {
2626
self.init(cgColor: light.cgColor)
2727
}
2828
}

Source/WithError.swift

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
//
2+
// WithError.swift
3+
// CoreModule
4+
//
5+
// Created by Maxim Ivanov on 29.07.2023.
6+
//
7+
8+
public struct WithError: Error, Equatable, CustomStringConvertible {
9+
10+
public let base: Error
11+
12+
private let equals: (Error) -> Bool
13+
14+
public init<Base: Error>(_ base: Base) {
15+
self.base = base
16+
self.equals = { String(reflecting: $0) == String(reflecting: base) }
17+
}
18+
19+
public init<Base: Error & Equatable>(_ base: Base) {
20+
self.base = base
21+
self.equals = { ($0 as? Base) == base }
22+
}
23+
24+
public static func == (lhs: WithError, rhs: WithError) -> Bool {
25+
lhs.equals(rhs.base)
26+
}
27+
28+
public var description: String {
29+
"\(self.base)"
30+
}
31+
32+
public func asError<Base: Error>(type: Base.Type) -> Base? {
33+
self.base as? Base
34+
}
35+
36+
public var localizedDescription: String {
37+
self.base.localizedDescription
38+
}
39+
}
40+
41+
extension Error where Self: Equatable {
42+
public func withError() -> WithError {
43+
WithError(self)
44+
}
45+
}
46+
47+
extension Error {
48+
public func withError() -> WithError {
49+
WithError(self)
50+
}
51+
}

0 commit comments

Comments
 (0)