Skip to content

Commit

Permalink
[Enhancement] Communications library for non Apple platforms (#15)
Browse files Browse the repository at this point in the history
This PR contains the work done to allow the `MakeURLRequestUseCase` use case to be used in non-Apple platforms, as it use has been restricted before.

To provide further details about the work done:
- [x] improved the `MakeURLRequestUseCase` use case to be available in non-Apple platforms;
- [x] moved the `TestEndpoint` helper endpoint to its own file;
- [x] moved some test cases files around;
- [x] updated some text in the `README` file.

Co-authored-by: Javier Cicchelli <javier@rock-n-code.com>
Reviewed-on: https://repo.rock-n-code.com/rock-n-code/swift-libs/pulls/15
  • Loading branch information
Javier Cicchelli and mr-rock committed Apr 30, 2023
1 parent 94a49af commit fb439a8
Show file tree
Hide file tree
Showing 6 changed files with 53 additions and 37 deletions.
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ To provide further details about the libraries included in this package:
* `Coordination`: protocols to implement the [Coordinator pattern](https://khanlou.com/2015/01/the-coordinator/) and some ready-to-use platform-specific concrete routers;
* `Core`: extensions we usually add to the base layer functionality and primitive types provided by the [Swift standard library](https://https://www.swift.org/documentation/#standard-library);
* `Dependencies`: a ready-to-use, simple [Dependency Injection](https://en.wikipedia.org/wiki/Dependency_injection) mechanism that levers heavily on the [dynamic property wrappers](https://www.hackingwithswift.com/plus/intermediate-swiftui/creating-a-custom-property-wrapper-using-dynamicproperty) provided by the [Swift programming language](https://docs.swift.org/swift-book/documentation/the-swift-programming-language/properties/#Projecting-a-Value-From-a-Property-Wrapper);
* `Persistence`: protocols, extensions and a ready-to-use fetcher class to simplify the building of the [CoreData](https://developer.apple.com/documentation/coredata) persistence layer;
* `Persistence` (*available for Apple platforms only*): protocols, extensions and a ready-to-use fetcher class to simplify the building of the [CoreData](https://developer.apple.com/documentation/coredata) persistence layer;

## Installation

Expand Down Expand Up @@ -73,6 +73,6 @@ In an opened Xcode project, it is required to follow these steps to install the

### Other considerations

This library is fully supported on Apple platforms: *iOS*, *macOS*, *tvOS*, and *watchOS*. In addition, basic support for *Linux* platform has been added as well, but it is rather limited for the time being, but it is just a matter of time as the Foundation framework is [moving towards cross-platform support](https://www.swift.org/blog/foundation-preview-now-available).
This library is fully supported on Apple platforms: *iOS*, *macOS*, *tvOS*, and *watchOS*. In addition, basic support for *Linux* platform has been added as well, but it is rather limited for the time being. It is just a matter of time, though, as the Foundation framework is [moving towards cross-platform support](https://www.swift.org/blog/foundation-preview-now-available) by moving away from its dependency on legacy Objective-C components.

⚠️ Please notice that this library only supports the [Swift Package Manager](https://www.swift.org/package-manager/), and that support for other dependency managers such as *Cocoapods* and *Carthage* has not been prioritised.
6 changes: 4 additions & 2 deletions Sources/Communications/Use Cases/MakeURLRequestUseCase.swift
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,12 @@
//
//===----------------------------------------------------------------------===//

#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
import Foundation

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

/// This use case generate a url request out of a given endpoint.
public struct MakeURLRequestUseCase {

Expand Down Expand Up @@ -56,4 +59,3 @@ public struct MakeURLRequestUseCase {
}

}
#endif
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,14 @@
//
//===----------------------------------------------------------------------===//

#if os(iOS) || os(macOS) || os(tvOS) || os(watchOS)
import Communications
import Foundation
import XCTest

#if canImport(FoundationNetworking)
import FoundationNetworking
#endif

final class MakeURLRequestUseCaseTests: XCTestCase {

// MARK: Properties
Expand Down Expand Up @@ -111,35 +114,3 @@ final class MakeURLRequestUseCaseTests: XCTestCase {
}

}

// MARK: - TestEndpoint

private struct TestEndpoint: Endpoint {

// MARK: Properties

let scheme: String = "http"
let host: String = "www.something.com"
let port: Int?
let path: String = "/path/to/endpoint"
let parameters: Parameters
let method: HTTPRequestMethod = .get
let headers: Headers
let body: Data?

// MARK: Initialisers

init(
port: Int? = nil,
parameters: Parameters = [:],
headers: Headers = [:],
body: Data? = nil
) {
self.port = port
self.parameters = parameters
self.headers = headers
self.body = body
}

}
#endif
43 changes: 43 additions & 0 deletions Tests/Communications/Helpers/Endpoints/TestEndpoint.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
//===----------------------------------------------------------------------===//
//
// This source file is part of the SwiftLibs open source project
//
// Copyright (c) 2023 Röck+Cöde VoF. and the SwiftLibs project authors
// Licensed under the EUPL 1.2 or later.
//
// See LICENSE.txt for license information
// See CONTRIBUTORS.txt for the list of SwiftLibs project authors
//
//===----------------------------------------------------------------------===//

import Communications
import Foundation

struct TestEndpoint: Endpoint {

// MARK: Properties

let scheme: String = "http"
let host: String = "www.something.com"
let port: Int?
let path: String = "/path/to/endpoint"
let parameters: Parameters
let method: HTTPRequestMethod = .get
let headers: Headers
let body: Data?

// MARK: Initialisers

init(
port: Int? = nil,
parameters: Parameters = [:],
headers: Headers = [:],
body: Data? = nil
) {
self.port = port
self.parameters = parameters
self.headers = headers
self.body = body
}

}
File renamed without changes.

0 comments on commit fb439a8

Please sign in to comment.