Skip to content

Commit 4c0a5a2

Browse files
committed
feat: make DomainList module and NetworkViewer sdk class
1 parent 077b7c2 commit 4c0a5a2

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

44 files changed

+490
-442
lines changed

Package.swift

Lines changed: 1 addition & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,16 @@ let package = Package(
77
name: "NetworkViewer",
88
platforms: [.iOS(.v14)],
99
products: [
10-
// Products define the executables and libraries a package produces, and make them visible to other packages.
1110
.library(
1211
name: "NetworkViewer",
1312
targets: ["NetworkViewer"]
1413
),
1514
],
1615
dependencies: [],
1716
targets: [
18-
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
19-
// Targets can depend on other targets in this package, and on products in packages this package depends on.
2017
.target(
2118
name: "NetworkViewer",
22-
dependencies: [],
23-
resources: [
24-
.process("Resources"),
25-
]
19+
dependencies: []
2620
)
2721
]
2822
)

Sources/NetworkViewer/Common/Debug/RainbowDebugModifier.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ import SwiftUI
99

1010
private let rainbowDebugColors = [Color.purple, Color.blue, Color.green, Color.yellow, Color.orange, Color.red]
1111

12-
public extension View {
12+
extension View {
1313

1414
/// Useful modifier for debugging view redrawing
1515
@ViewBuilder

Sources/NetworkViewer/Common/Extensions/Extension+EdgeInsets.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Foundation
88
import SwiftUI
99

10-
public extension EdgeInsets {
10+
extension EdgeInsets {
1111

1212
static var zero: EdgeInsets = .init(top: 0, leading: 0, bottom: 0, trailing: 0)
1313
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//
2+
// public extension + UIWindow.swift
3+
// Olimp
4+
//
5+
// Created by Artem Balashov on 12/03/2019.
6+
// Copyright © 2019 Egor Sakhabaev. All rights reserved.
7+
//
8+
9+
import Foundation
10+
import UIKit
11+
12+
extension UIApplication {
13+
14+
class func topViewController(
15+
controller: UIViewController? = nil
16+
) -> UIViewController? {
17+
var controller = controller
18+
if controller == nil {
19+
let windows = UIApplication.shared.windows
20+
let window = windows.first { $0.isKeyWindow } ?? windows.first
21+
controller = window?.rootViewController
22+
}
23+
if
24+
let navigationController = controller as? UINavigationController,
25+
let visibleController = navigationController.visibleViewController
26+
{
27+
return topViewController(controller: visibleController)
28+
}
29+
if let tabController = controller as? UITabBarController {
30+
if let selected = tabController.selectedViewController {
31+
return topViewController(controller: selected)
32+
}
33+
}
34+
if let presented = controller?.presentedViewController {
35+
return topViewController(controller: presented)
36+
}
37+
return controller
38+
}
39+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
//
2+
// File.swift
3+
//
4+
//
5+
// Created by Sakhabaev Egor on 10.11.2023.
6+
//
7+
8+
import Foundation
9+
10+
public struct CustomError: Codable {
11+
12+
public let code: Int
13+
public let message: String
14+
15+
public init(code: Int, message: String) {
16+
self.code = code
17+
self.message = message
18+
}
19+
20+
public init(_ error: NSError) {
21+
self.init(code: error.code, message: error.localizedDescription)
22+
}
23+
24+
public init(_ error: Error) {
25+
let nsError = error as NSError
26+
self.init(nsError)
27+
}
28+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
//
2+
// Header.swift
3+
//
4+
//
5+
// Created by Sakhabaev Egor on 10.11.2023.
6+
//
7+
8+
import Foundation
9+
10+
public struct Header: Codable {
11+
12+
public let key: String
13+
public let value: String
14+
15+
public init(key: String, value: String) {
16+
self.key = key
17+
self.value = value
18+
}
19+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//
2+
// Operation.swift
3+
//
4+
//
5+
// Created by Sakhabaev Egor on 10.11.2023.
6+
//
7+
8+
import Foundation
9+
10+
public struct Operation {
11+
12+
let request: Request
13+
let response: Response?
14+
let error: CustomError?
15+
16+
public init(request: Request, response: Response?, error: CustomError?) {
17+
self.request = request
18+
self.response = response
19+
self.error = error
20+
}
21+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
//
2+
// Request.swift
3+
//
4+
//
5+
// Created by Sakhabaev Egor on 10.11.2023.
6+
//
7+
8+
import Foundation
9+
10+
public struct Request: Codable {
11+
12+
public let url: String
13+
public let method: String
14+
public let headers: [Header]
15+
public let body: Data?
16+
17+
public init(url: String, method: String, headers: [Header], body: Data?) {
18+
self.url = url
19+
self.method = method
20+
self.headers = headers
21+
self.body = body
22+
}
23+
24+
public init(_ urlRequest: URLRequest) {
25+
url = urlRequest.url?.absoluteString ?? "-"
26+
method = urlRequest.httpMethod ?? "-"
27+
headers = urlRequest.allHTTPHeaderFields?.map { Header(key: $0.key, value: $0.value ) } ?? []
28+
body = urlRequest.httpBody
29+
}
30+
}
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
//
2+
// Response.swift
3+
//
4+
//
5+
// Created by Sakhabaev Egor on 10.11.2023.
6+
//
7+
8+
import Foundation
9+
10+
public struct Response: Codable {
11+
12+
public let statusCode: Int
13+
public let headers: [Header]
14+
15+
public init(statusCode: Int, headers: [Header]) {
16+
self.statusCode = statusCode
17+
self.headers = headers
18+
}
19+
20+
public init?(_ response: URLResponse) {
21+
if let httpResponse = response as? HTTPURLResponse {
22+
statusCode = httpResponse.statusCode
23+
headers = httpResponse.allHeaderFields.map {
24+
Header(
25+
key: $0.key as? String ?? "Unknown Key",
26+
value: $0.value as? String ?? "Unknown Value"
27+
)
28+
}
29+
} else {
30+
statusCode = 200
31+
headers = [
32+
Header(key: "Content-Length", value: "\(response.expectedContentLength)"),
33+
Header(key: "Content-Type", value: response.mimeType ?? "plain/text")
34+
]
35+
}
36+
}
37+
}

Sources/NetworkViewer/Common/Modifiers/HideScrollndicatorsModifier.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
import Foundation
88
import SwiftUI
99

10-
public struct HideScrollndicatorsModifier: ViewModifier {
10+
struct HideScrollndicatorsModifier: ViewModifier {
1111

1212
@ViewBuilder
1313
public func body(content: Content) -> some View {
@@ -20,7 +20,7 @@ public struct HideScrollndicatorsModifier: ViewModifier {
2020
}
2121
}
2222

23-
public extension View {
23+
extension View {
2424

2525
func hideScrollIndicators() -> some View {
2626
modifier(HideScrollndicatorsModifier())

0 commit comments

Comments
 (0)