Skip to content

Commit

Permalink
fix conversation
Browse files Browse the repository at this point in the history
Signed-off-by: PhongND <phongnd@ftech.ai>
  • Loading branch information
PhongND committed Oct 6, 2023
1 parent 23e446c commit bdb482f
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 8 deletions.
Binary file not shown.
7 changes: 0 additions & 7 deletions Sources/BuildRequest/Core/RequestProtocol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,7 @@ extension RequestProtocol {

public func executing(request: inout URLRequest, requests: [RequestProtocol] = []) {
if requests.isEmpty { return }
// var items: [RequestProtocol] = []
// items.append(contentsOf: requests.filter({$0 is RUrl}))
// items.append(contentsOf: requests.filter({$0 is RPath}))
// items.append(contentsOf: requests.filter({!($0 is RUrl || $0 is REncoding || $0 is RPath)}))
// items.append(contentsOf: requests.filter({$0 is REncoding}))

let items: [RequestProtocol] = requests.cRequests()
/// build
items.forEach {
$0.build(request: &request)
}
Expand Down
20 changes: 20 additions & 0 deletions Sources/BuildRequest/RequestBuilds/RQueryItems.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@ public struct RQueryItems: RequestProtocol {
} ?? []
}

public init(_ queryItem: Data? = nil) {
self.init(queryItem?.toDictionary())
}

public init(_ queryItem: String? = nil) {
self.init(queryItem?.toDictionary())
}

public init(_ params: [RQueryItem]) {
self.children = params
}
Expand All @@ -29,6 +37,18 @@ extension RQueryItems {
public init(_ initial: () -> [String: Any]?) {
self.init(initial())
}

public init(_ initial: () -> Data?) {
self.init(initial()?.toDictionary())
}

public init(_ initial: () -> String?) {
self.init(initial()?.toDictionary())
}

public init(_ initial: () -> [RQueryItem]) {
self.init(initial())
}
}

extension RQueryItems {
Expand Down
15 changes: 14 additions & 1 deletion Sources/BuildRequest/RequestBuilds/RUrl.swift
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
import Foundation

public struct RUrl: RequestProtocol {
private let urlString: String

public var urlString: String

public init(_ urlString: String) {
self.urlString = urlString
Expand All @@ -13,6 +14,18 @@ public struct RUrl: RequestProtocol {
}

extension RUrl {

/// Init with computed closure
///```swift
///RUrl("path")
/// .withPath("otherPaht")
/// .with {
/// $0.urlString += "other" // updating urlstring
/// print($0.urlString)
/// }
///
///```
/// - Parameter initial: A closure return a string url.
public init(_ initial: () -> String) {
self.init(initial())
}
Expand Down
6 changes: 6 additions & 0 deletions Tests/BuildRequestTests/BuildRequestTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -211,4 +211,10 @@ final class BuildRequestTest: XCTestCase {
let sequence = _SequenceMany(requests: requests)
print(sequence)
}

func test_rurl() {
let url = RUrl("")
.withPath("ABC")
.with { $0.path }
}
}

0 comments on commit bdb482f

Please sign in to comment.