Skip to content

Commit

Permalink
Merge pull request #23 from openedx/develop
Browse files Browse the repository at this point in the history
Develop to main
  • Loading branch information
IvanStepanok authored Nov 18, 2024
2 parents fbd8c9c + a7105a1 commit b0ce257
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 26 deletions.
19 changes: 14 additions & 5 deletions Package.resolved
Original file line number Diff line number Diff line change
@@ -1,22 +1,31 @@
{
"originHash" : "5e69a65bc13b6866cc012a28d126dae3f03ac53e850f32034103be9b5d345cad",
"originHash" : "0176ca547be3045c0dad664f8065b6354d9a070d44592acf4b047888e61a7f21",
"pins" : [
{
"identity" : "alamofire",
"kind" : "remoteSourceControl",
"location" : "https://github.com/Alamofire/Alamofire.git",
"state" : {
"revision" : "b2fa556e4e48cbf06cf8c63def138c98f4b811fa",
"version" : "5.8.0"
"revision" : "e16d3481f5ed35f0472cb93350085853d754913f",
"version" : "5.10.1"
}
},
{
"identity" : "keychain-swift",
"kind" : "remoteSourceControl",
"location" : "https://github.com/evgenyneu/keychain-swift.git",
"state" : {
"revision" : "5e1b02b6a9dac2a759a1d5dbc175c86bd192a608",
"version" : "24.0.0"
}
},
{
"identity" : "kingfisher",
"kind" : "remoteSourceControl",
"location" : "https://github.com/onevcat/Kingfisher.git",
"state" : {
"revision" : "b6f62758f21a8c03cd64f4009c037cfa580a256e",
"version" : "7.9.1"
"revision" : "c0940e241945e6378c01fbd45fd3815579d47ef5",
"version" : "8.1.0"
}
},
{
Expand Down
14 changes: 8 additions & 6 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,12 @@ let package = Package(
)
],
dependencies: [
.package(url: "https://github.com/Alamofire/Alamofire.git", exact: "5.8.0"),
.package(url: "https://github.com/onevcat/Kingfisher.git", exact: "7.9.1"),
.package(url: "https://github.com/siteline/swiftui-introspect", from: "1.3.0"),
.package(url: "https://github.com/Swinject/Swinject.git", from: "2.9.1"),
.package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", from: "0.57.0")
.package(url: "https://github.com/Alamofire/Alamofire.git", exact: "5.10.1"),
.package(url: "https://github.com/onevcat/Kingfisher.git", exact: "8.1.0"),
.package(url: "https://github.com/siteline/swiftui-introspect", exact: "1.3.0"),
.package(url: "https://github.com/Swinject/Swinject.git", exact: "2.9.1"),
.package(url: "https://github.com/SimplyDanny/SwiftLintPlugins", exact: "0.57.0"),
.package(url: "https://github.com/evgenyneu/keychain-swift.git", exact: "24.0.0")
],
targets: [
.target(
Expand All @@ -30,7 +31,8 @@ let package = Package(
.product(name: "Alamofire", package: "Alamofire"),
.product(name: "Kingfisher", package: "Kingfisher"),
.product(name: "SwiftUIIntrospect", package: "swiftui-introspect"),
.product(name: "Swinject", package: "Swinject")
.product(name: "Swinject", package: "Swinject"),
.product(name: "KeychainSwift", package: "keychain-swift")
],
plugins: [
.plugin(name: "SwiftLintBuildToolPlugin", package: "SwiftLintPlugins")
Expand Down
8 changes: 6 additions & 2 deletions Sources/OEXFoundation/Extensions/DispatchQueue+App.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@

import Foundation

public func doAfter(_ delay: TimeInterval? = nil, _ closure: @Sendable @escaping () -> Void) {
DispatchQueue.main.asyncAfter(deadline: .now() + (delay ?? 0), execute: closure)
@MainActor
public func doAfter(_ delay: TimeInterval? = nil, _ closure: @escaping () -> Void) {
Task {
try? await Task.sleep(for: .milliseconds((delay ?? 0) * 1000))
closure()
}
}

public func dispatchQueueMain(_ closure: @Sendable @escaping () -> Void) {
Expand Down
23 changes: 12 additions & 11 deletions Sources/OEXFoundation/Network/API.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import Foundation
import Alamofire
import WebKit

public final class API {
public final class API: Sendable {

let session: Alamofire.Session
let baseURL: URL
private let session: Alamofire.Session
private let baseURL: URL

public init(session: Session, baseURL: URL) {
self.session = session
Expand Down Expand Up @@ -197,18 +197,16 @@ public enum APIError: Int, LocalizedError {
}
}

public struct CustomValidationError: LocalizedError {
public struct CustomValidationError: LocalizedError, Sendable {
public let statusCode: Int
public let data: [String: Any]?
public let data: [String: any Any & Sendable]?

public init(statusCode: Int, data: [String: Any]?) {
public init(statusCode: Int, data: [String: any Any & Sendable]?) {
self.statusCode = statusCode
self.data = data
}
}

extension CustomValidationError: @unchecked Sendable {}

extension DataRequest {
func validateResponse() -> Self {
return validateStatusCode().validateContentType()
Expand All @@ -223,7 +221,10 @@ extension DataRequest {
if let data {
if let dataString = String(data: data, encoding: .utf8) {
if dataString.first == "{" && dataString.last == "}" {
let json = try? JSONSerialization.jsonObject(with: data, options: []) as? [String: Any]
let json = try? JSONSerialization.jsonObject(
with: data,
options: []
) as? [String: any Any & Sendable]
return .failure(CustomValidationError(statusCode: response.statusCode, data: json))
} else {
let reason: AFError.ResponseValidationFailureReason
Expand Down Expand Up @@ -262,12 +263,12 @@ public struct CustomGetEncoding: ParameterEncoding {
}

extension Encodable {
func asDictionary() throws -> [String: Any] {
func asDictionary() throws -> [String: any Any & Sendable] {
let data = try JSONEncoder().encode(self)
guard let dictionary = try JSONSerialization.jsonObject(
with: data,
options: .fragmentsAllowed
) as? [String: Any] else {
) as? [String: any Any & Sendable] else {
throw NSError(
domain: "com.oexfoundation.error",
code: 1,
Expand Down
2 changes: 1 addition & 1 deletion Sources/OEXFoundation/Network/HeadersRedirectHandler.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Foundation
import Alamofire

public class HeadersRedirectHandler: RedirectHandler {
public final class HeadersRedirectHandler: RedirectHandler {

public init() {
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/OEXFoundation/Network/NetworkLogger.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import Alamofire
import Foundation

public class NetworkLogger: EventMonitor {
public final class NetworkLogger: EventMonitor {

public let queue = DispatchQueue(label: "com.raccoongang.networklogger")

Expand Down

0 comments on commit b0ce257

Please sign in to comment.