Skip to content

Commit 9c17698

Browse files
authored
Merge pull request #2 from neothXT/package-rename
package rename to SwiftNet
2 parents 2e9fe2e + f285947 commit 9c17698

Some content is hidden

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

55 files changed

+358
-358
lines changed

Package.swift

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,19 +5,19 @@ import PackageDescription
55
import CompilerPluginSupport
66

77
let package = Package(
8-
name: "CombineNetworking",
8+
name: "SwiftNet",
99
platforms: [
1010
.macOS(.v10_15),
1111
.iOS(.v13)
1212
],
1313
products: [
1414
// Products define the executables and libraries a package produces, and make them visible to other packages.
1515
.library(
16-
name: "CombineNetworking",
17-
targets: ["CombineNetworking"]),
16+
name: "SwiftNet",
17+
targets: ["SwiftNet"]),
1818
.library(
19-
name: "CombineNetworkingMacros",
20-
targets: ["CombineNetworkingMacros"])
19+
name: "SwiftNetMacros",
20+
targets: ["SwiftNetMacros"])
2121
],
2222
dependencies: [
2323
// Dependencies declare other packages that this package depends on.
@@ -28,26 +28,26 @@ let package = Package(
2828
// Targets are the basic building blocks of a package. A target can define a module or a test suite.
2929
// Targets can depend on other targets in this package, and on products in packages this package depends on.
3030
.macro(
31-
name: "CNMacros",
31+
name: "SNMacros",
3232
dependencies: [
3333
.product(name: "SwiftSyntaxMacros", package: "swift-syntax"),
3434
.product(name: "SwiftCompilerPlugin", package: "swift-syntax"),
35-
"CombineNetworking"
35+
"SwiftNet"
3636
]
3737
),
3838
.target(
39-
name: "CombineNetworking",
39+
name: "SwiftNet",
4040
exclude: ["../../CombineNetworking.podspec"]),
4141
.testTarget(
42-
name: "CombineNetworkingTests",
43-
dependencies: ["CombineNetworking", "CombineNetworkingMacros", "CNMacros"]),
42+
name: "SwiftNetTests",
43+
dependencies: ["SwiftNet", "SwiftNetMacros", "SNMacros"]),
4444
.target(
45-
name: "CombineNetworkingMacros",
46-
dependencies: ["CNMacros", "CombineNetworking"]),
45+
name: "SwiftNetMacros",
46+
dependencies: ["SNMacros", "SwiftNet"]),
4747
.testTarget(
48-
name: "CombineNetworkingMacrosTests",
48+
name: "SwiftNetMacrosTests",
4949
dependencies: [
50-
"CombineNetworkingMacros",
50+
"SwiftNetMacros",
5151
.product(name: "SwiftSyntaxMacrosTestSupport", package: "swift-syntax")
5252
]
5353
)

README.md

Lines changed: 34 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
1-
![alt [version]](https://img.shields.io/github/v/release/neothXT/CombineNetworking) ![alt cocoapods available](https://img.shields.io/badge/CocoaPods-v1.11.0-blue) ![alt spm available](https://img.shields.io/badge/SPM-available-green) ![alt carthage unavailable](https://img.shields.io/badge/Carthage-unavailable-red)
1+
![alt [version]](https://img.shields.io/github/v/release/neothXT/SwiftNet) ![alt cocoapods available](https://img.shields.io/badge/CocoaPods-v1.11.0-blue) ![alt spm available](https://img.shields.io/badge/SPM-available-green) ![alt carthage unavailable](https://img.shields.io/badge/Carthage-unavailable-red)
22

3-
# CombineNetworking
4-
Meet CombineNetworking. Super lightweight and crazy easy to use framework to help you create and handle your network requests in a convenient way.
5-
Besides basic network requests, CombineNetworking allows you to easily send your requests securely with a simple SSL and Certificate pinning mechanisms. But that's not all. With CombineNetworking you can also effortlessly handle authorization tokens with built-in automatic authorization mechanism.
3+
# SwiftNet
4+
Meet SwiftNet. Super lightweight and crazy easy to use framework to help you create and handle your network requests in a convenient way.
5+
Besides basic network requests, SwiftNet allows you to easily send your requests securely with a simple SSL and Certificate pinning mechanisms. But that's not all. With SwiftNet you can also effortlessly handle authorization tokens with built-in automatic authorization mechanism.
66

77
## Installation (using CocoaPods)
88

99
`pod 'CombineNetworking'`
1010

11-
##### Note that in order to use CombineNetworking, your iOS Deployment Target has to be 13.0 or newer. If you code for macOS, your Deployment Target has to be 10.15 or newer.
11+
##### Note that in order to use SwiftNet, your iOS Deployment Target has to be 13.0 or newer. If you code for macOS, your Deployment Target has to be 10.15 or newer.
1212

13-
#### CombineNetworking 2.0.0 and above won't be available on CocoaPods unless SwiftSyntax package (which is required to enable Swift Macros) becomes available on CocoaPods. To fetch the latest versions, please use SPM (Swift Package Manager).
13+
#### SwiftNet 2.0.0 and above won't be available on CocoaPods unless SwiftSyntax package (which is required to enable Swift Macros) becomes available on CocoaPods. To fetch the latest versions, please use SPM (Swift Package Manager).
1414

1515
## Key functionalities
1616
- Sending requests easily using `Endpoint` models
1717
- SSL and Certificate pinning with just 2 lines of code
18-
- WebSocket connection support with `CNWebSocket`
18+
- WebSocket connection support with `SNWebSocket`
1919
- Secure access token storage with Keychain
2020
- Access token storing strategy - configure `global`, `endpoint specific` (`default`) or `custom` strategy for all or just some endpoints
2121
- Automated refresh token/callback requests
@@ -76,14 +76,14 @@ extension TodosEndpoint: Endpoint {
7676
To turn SSL and/or Certificate pinning in your app just add:
7777

7878
```Swift
79-
CNConfig.pinningModes = [.ssl, .certificate]
79+
SNConfig.pinningModes = [.ssl, .certificate]
8080
```
8181

82-
Please remember that SSL/Certificate pinning requires certificate file to be attached in your project. Certificates and SSL keys are autmatically loaded by CombineNetworking.
82+
Please remember that SSL/Certificate pinning requires certificate file to be attached in your project. Certificates and SSL keys are autmatically loaded by SwiftNet.
8383

8484
### Automatic authorization mechanism
8585

86-
Handling authorization callbacks with CombineNetworking is ridiculously easy. To use it with your `Endpoint` all you have to do is to add `requiresAccessToken` and `callbackPublisher` fields as presented below:
86+
Handling authorization callbacks with SwiftNet is ridiculously easy. To use it with your `Endpoint` all you have to do is to add `requiresAccessToken` and `callbackPublisher` fields as presented below:
8787

8888
```Swift
8989

@@ -108,31 +108,31 @@ extension TodosEndpoint: Endpoint {
108108

109109
//... and prepare callbackPublisher to handle authorization callbacks
110110
var callbackPublisher: AnyPublisher<AccessTokenConvertible?, Error>? {
111-
try? CNProvider<TodosEndpoint>().publisher(for: .token, responseType: CNAccessToken?.self).asAccessTokenConvertible()
111+
try? SNProvider<TodosEndpoint>().publisher(for: .token, responseType: SNAccessToken?.self).asAccessTokenConvertible()
112112
}
113113
}
114114
```
115115

116116
See? Easy peasy! Keep in mind that your token model has to conform to `AccessTokenConvertible`.
117117

118-
### CNConfig properties and methods
118+
### SNConfig properties and methods
119119

120120
- `pinningModes` - turns on/off SSL and Certificate pinning. Available options are `.ssl`, `.certificate` or both.
121121
- `sitesExcludedFromPinning` - list of website addresses excluded from SSL/Certificate pinning check
122122
- `defaultJSONDecoder` - use this property to set globally your custom JSONDecoder
123123
- `defaultAccessTokenStrategy` - global strategy for storing access tokens. Available options are `.global` and `.custom(String)`.
124-
- `keychainInstance` - keychain instance used by CombineNetworking to store/fetch access tokens from Apple's Keychain. If not provided, safe storage will be turned off (more info below)
125-
- `accessTokenStorage` - an instance of an object implementing AccessTokenStorage protocol. It's used to manipulate access token. By default it uses built-in `CNStorage`. To use different storage, provide your own instance.
124+
- `keychainInstance` - keychain instance used by SwiftNet to store/fetch access tokens from Apple's Keychain. If not provided, safe storage will be turned off (more info below)
125+
- `accessTokenStorage` - an instance of an object implementing AccessTokenStorage protocol. It's used to manipulate access token. By default it uses built-in `SNStorage`. To use different storage, provide your own instance.
126126
- `accessTokenErrorCodes` - array containing error codes that should trigger access token refresh action. Default: [401].
127127

128128
### Access Token Strategies
129129

130-
CombineNetworking allows you to specify access token strategies globally as well as individually for each endpoint. You can specify your strategy by setting it for `CNConfig.defaultAccessTokenStrategy` or inside your `Endpoint` by setting value for field `accessTokenStrategy`.
130+
SwiftNet allows you to specify access token strategies globally as well as individually for each endpoint. You can specify your strategy by setting it for `SNConfig.defaultAccessTokenStrategy` or inside your `Endpoint` by setting value for field `accessTokenStrategy`.
131131
Available options are:
132132
- `.global` - uses global label to store access token
133133
- `.custom(String)` - with this option you can specify your own label to store access token and use it among as many endpoints as you wish
134134

135-
Thanks to access token strategy being set both globally (via `CNConfig`) and individually (inside `Endpoint`), you can mix different strategies in your app!
135+
Thanks to access token strategy being set both globally (via `SNConfig`) and individually (inside `Endpoint`), you can mix different strategies in your app!
136136

137137
### Access Token manipulations
138138

@@ -150,7 +150,7 @@ Available methods are:
150150

151151
### Event logging
152152

153-
CombineNetworking's CNProvider uses iOS built-in Logger (if running on iOS 14 or newer) and custom debug-mode-only logger by default for each and every request.
153+
SwiftNet's SNProvider uses iOS built-in Logger (if running on iOS 14 or newer) and custom debug-mode-only logger by default for each and every request.
154154

155155
### Network connection monitor
156156

@@ -161,7 +161,7 @@ If you want to subscribe to a network connection monitor's publisher, you can do
161161
private var subscriptions: Set<AnyCancellable> = []
162162

163163
func subscribeForNetworkChanges() {
164-
CNNetworkMonitor.publisher()
164+
SNNetworkMonitor.publisher()
165165
.sink { status in
166166
switch status {
167167
case .wifi:
@@ -178,17 +178,17 @@ func subscribeForNetworkChanges() {
178178

179179
### Safe storage using Keychain
180180

181-
CombineNetworking allows you to store your access tokens in keychain. Using keychain to store your access tokens requires you to provide keychain instance by setting value of `CNConfig.keychainInstance`.
181+
SwiftNet allows you to store your access tokens in keychain. Using keychain to store your access tokens requires you to provide keychain instance by setting value of `SNConfig.keychainInstance`.
182182

183-
Please remember Apple's Keychain doesn't automatically remove entries created by an app upon its deletion. Do not worry, however. Only your app can access those entries, nevertheless, it's up to you to make sure those are removed from keychain if not needed anymore. CombineNetworking provides method `CNConfig.removeAccessToken(...)` to help you do it.
183+
Please remember Apple's Keychain doesn't automatically remove entries created by an app upon its deletion. Do not worry, however. Only your app can access those entries, nevertheless, it's up to you to make sure those are removed from keychain if not needed anymore. SwiftNet provides method `SNConfig.removeAccessToken(...)` to help you do it.
184184
### Subscribe to a publisher
185185

186186
```Swift
187187
private var subscriptions: Set<AnyCancellable> = []
188188
var todo: Todo?
189189

190190
func subscribeForTodos() {
191-
CNProvider<TodosEndpoint>().publisher(for: .todos(1), responseType: Todo?.self)
191+
SNProvider<TodosEndpoint>().publisher(for: .todos(1), responseType: Todo?.self)
192192
.catch { (error) -> Just<Todo?> in
193193
print(error)
194194
return Just(nil)
@@ -202,22 +202,22 @@ If you want to subscribe to a publisher but doesn't want to immediately decode t
202202

203203
### Error handling
204204

205-
In case of request failure, CombineNetworking returns stuct of type `CNError` reflected as `Error`.
205+
In case of request failure, SwiftNet returns stuct of type `SNError` reflected as `Error`.
206206

207207
```Swift
208-
public struct CNError: Error {
208+
public struct SNError: Error {
209209
let type: ErrorType
210-
let details: CNErrorDetails?
210+
let details: SNErrorDetails?
211211
let data: Data?
212212
}
213213
```
214214

215215
Available error types are: `failedToBuildRequest`, `failedToMapResponse`, `unexpectedResponse`, `authenticationFailed`, `notConnected`, `emptyResponse`, `noInternetConnection` and `conversionFailed`.
216216

217-
`CNErrorDetails` looks like following:
217+
`SNErrorDetails` looks like following:
218218

219219
```Swift
220-
public struct CNErrorDetails {
220+
public struct SNErrorDetails {
221221
public let statusCode: Int
222222
public let localizedString: String
223223
public let url: URL?
@@ -232,8 +232,8 @@ public struct CNErrorDetails {
232232
If you want to run simple tests on your request, just to confirm the status code of the response met the expectations set for a given endpoint you can just run `testRaw()` method like this:
233233

234234
```Swift
235-
final class CombineNetworkingTests: XCTestCase {
236-
private let provider = CNProvider<RemoteEndpoint>()
235+
final class SwiftNetTests: XCTestCase {
236+
private let provider = SNProvider<RemoteEndpoint>()
237237

238238
func testTodoFetch() throws {
239239
let expectation = expectation(description: "Test todo fetching request")
@@ -251,8 +251,8 @@ final class CombineNetworkingTests: XCTestCase {
251251
... and if you want to test your request by confirming both the status code and the response model, use `test()` method like this:
252252

253253
```Swift
254-
final class CombineNetworkingTests: XCTestCase {
255-
private let provider = CNProvider<RemoteEndpoint>()
254+
final class SwiftNetTests: XCTestCase {
255+
private let provider = SNProvider<RemoteEndpoint>()
256256

257257
func testTodoFetchWithModel() throws {
258258
let expectation = expectation(description: "Test todo fetching request together with its response model")
@@ -271,10 +271,10 @@ You can also use mocked data in your tests. To do so, just add `mockedData` to y
271271

272272
### WebSockets
273273

274-
CombineNetworking also allows you to connect with WebSockets effortlessly. Simply use `CNWebSocket` like this:
274+
SwiftNet also allows you to connect with WebSockets effortlessly. Simply use `SNWebSocket` like this:
275275

276276
```Swift
277-
let webSocket = CNWebSocket(url: URL(string: "wss://socketsbay.com/wss/v2/2/demo/")!)
277+
let webSocket = SNWebSocket(url: URL(string: "wss://socketsbay.com/wss/v2/2/demo/")!)
278278
webSocket.connect()
279279
webSocket.listen { result in
280280
switch result {
@@ -301,7 +301,7 @@ If you want to close connection, just call `webSocket.disconnect()`.
301301

302302
## Macro-powered networking
303303

304-
From release 2.0.0 CombineNetworking introduces new way of building and executing network requests.
304+
From release 2.0.0 SwiftNet introduces new way of building and executing network requests.
305305

306306
### Endpoint creation
307307

@@ -405,7 +405,7 @@ func buildRequest() async throws -> [Comment] {
405405

406406
### Alternative "build a request" flow
407407

408-
From version 2.0.1 CombineNetworking allows you to speed things up even more by generating EndpointBuilders with descriptors. Thanks to descriptors, you can extract endpoint setup to reduce number of lines required to build working endpoint.
408+
From version 2.0.1 SwiftNet allows you to speed things up even more by generating EndpointBuilders with descriptors. Thanks to descriptors, you can extract endpoint setup to reduce number of lines required to build working endpoint.
409409

410410
```Swift
411411

Sources/CombineNetworking/Data/AccessTokenStorage.swift

Lines changed: 0 additions & 52 deletions
This file was deleted.
File renamed without changes.
File renamed without changes.
File renamed without changes.
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// CNDiagnostics.swift
2+
// SNDiagnostics.swift
33
//
44
//
55
// Created by Maciej Burdzicki on 18/06/2023.
@@ -10,7 +10,7 @@ import SwiftSyntax
1010
import SwiftDiagnostics
1111
import SwiftSyntaxBuilder
1212

13-
enum EndpointMacroError: CNDiagnostics, CustomStringConvertible, Error {
13+
enum EndpointMacroError: SNDiagnostics, CustomStringConvertible, Error {
1414
case badType, badInheritance, badOrMissingParameter
1515

1616
var domain: String { "endpoint" }
@@ -27,7 +27,7 @@ enum EndpointMacroError: CNDiagnostics, CustomStringConvertible, Error {
2727
}
2828
}
2929

30-
enum NetworkRequestMacroError: CNDiagnostics, CustomStringConvertible, Error {
30+
enum NetworkRequestMacroError: SNDiagnostics, CustomStringConvertible, Error {
3131
case typeNotRecognized, badType(macroName: String), badOrMissingUrlParameter, badOrMissingMethodParameter, syntaxError
3232

3333
var domain: String { "network request" }
@@ -48,17 +48,17 @@ enum NetworkRequestMacroError: CNDiagnostics, CustomStringConvertible, Error {
4848
}
4949
}
5050

51-
protocol CNDiagnostics {
51+
protocol SNDiagnostics {
5252
var domain: String { get }
5353
var description: String { get }
5454
func diagnostic(for node: SyntaxProtocol, severity: DiagnosticSeverity, fixIts: [FixIt]) -> Diagnostic
5555
}
5656

57-
extension CNDiagnostics {
57+
extension SNDiagnostics {
5858
func diagnostic(for node: SyntaxProtocol, severity: DiagnosticSeverity = .error, fixIts: [FixIt] = []) -> Diagnostic {
5959
.init(
6060
node: Syntax(node),
61-
message: CNDiagnosticMessage(
61+
message: SNDiagnosticMessage(
6262
diagnosticID: .init(domain: domain,id: String(describing: self)),
6363
message: description, severity: severity),
6464
fixIts: fixIts)
@@ -70,7 +70,7 @@ struct FixItMsg: FixItMessage {
7070
var message: String
7171
}
7272

73-
fileprivate struct CNDiagnosticMessage: DiagnosticMessage {
73+
fileprivate struct SNDiagnosticMessage: DiagnosticMessage {
7474
var diagnosticID: MessageID
7575
var message: String
7676
var severity: DiagnosticSeverity
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import SwiftCompilerPlugin
22
import SwiftSyntaxMacros
33

44
@main
5-
struct CNMacrosPlugin: CompilerPlugin {
5+
struct SNMacrosPlugin: CompilerPlugin {
66
let providingMacros: [Macro.Type] = [
77
EndpointMacro.self,
88
NetworkRequestMacro.self,

Sources/CombineNetworking/Config/AccessTokenStrategy.swift renamed to Sources/SwiftNet/Config/AccessTokenStrategy.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public enum AccessTokenStrategy {
1111
var storingLabel: String {
1212
switch self {
1313
case .global:
14-
return "accessToken_CombineNetworking"
14+
return "accessToken_SwiftNet"
1515
case .custom(let label):
1616
return "accessToken_\(label)"
1717
}

0 commit comments

Comments
 (0)